New answers tagged

0

If you don't want to patch the core you can create an EventSubscriber that attaches the view filter to the ajax command. After adding this your can use hook_form_alter to alter the filter. The subscriber looks like this. file: yourmodule.services.yml services: yourmodule.ajax_respose_subscriber: class: Drupal\yourmodule\EventSubscriber\...


0

You can do it using template_preprocess_form_element something like: use Drupal\Component\Utility\Html; function [YOURTHEME]_preprocess_form_element(&$variables) { $input_types = ['search', 'textfield', 'password']; $type = $variables['element']['#type'] ?? NULL; if (in_array($type, $input_types)) { $variables['element']['#attributes']['class']...


1

This is a variation of a frequently asked question. The user login form for Drupal is built using Drupal Form API. In Drupal 7 core, the user login form is declared in user.module: https://github.com/drupal/drupal/blob/7.x/modules/user/user.module#L2111 // Display login form: $form['name'] = array('#type' => 'textfield', '#title' => t('...


1

This: (isset($values['element1'])) will always return TRUE, since the form element exists, and therefore a value is always passed to the submit hander, even when the value is empty. You likely want this: !empty($values['element1'])


0

So, if dont want to use conditional_fields module and only conditional fields core You can do it, but required field have sometime a little bug. In the issue someone take some code from conditional_fields that fix this issue, and use it. your_module/js/conditional_fields.js (function ($, Drupal) { // Fix core's required handling. $(document).bind('state:...


1

This doesn't answer the question itself, but since I struggled for a while to get this all syncd up I figured I should drop the work into something that people might hit from google. To get the attributes all syncd up you can use the following js file: (function ($, Drupal, drupalSettings) { var handler = Drupal.behaviors.commentsRatingFlexible = { ...


0

I faced the same issue. This works fine for me, although I don't like inlining this piece of js and would move it to a .js file. $form['actions']['submit']['#attributes']['onclick'][] = " event.preventDefault(); if (!form.reportValidity()) { form.reportValidity(); } else { jQuery(this).after('<div class=\"ajax-progress ajax-progress-...


0

You may have troubles with file storage. It can mark your file as temporary file. And it will disappear after file cron. So it's better to consider this topic to prevent Drupal doing it. $file->setPermanent(); $file->save(); // Add to file usage calculation. \Drupal::service('file.usage')->add($file, 'my_module_name', 'file', $file->id());


0

The default_value attribute accept an array in case of managed_file: $form['my_file'] = [ '#type' => 'managed_file', '#title' => 'my file', '#name' => 'my_custom_file', '#description' => $this->t('my file description'), '#default_value' => [$config->get('my_file')], '#upload_location' => 'public:/...


1

To get a triggering element you must provide a unique '#name' for each button. Additionally, you can specify parameters to identify the action and record function example_form($form, &$form_state){ $form['groups'] = array( '#tree' => TRUE, ); foreach(array(5,4,8,10) AS $id){ $form['groups'][$id] = array( 'id' ...


0

In Drupal 8 It can be validated by the following code. /** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { // Validate email if (!\Drupal::service('email.validator')->isValid($form_state->getValues()['email'])) { $form_state->setErrorByName('Email', $this->t('Email address is not a ...


0

Little late to the game here,but in case anyone is still looking for answers, there is the Webform Content Creator module which will create a designated content type from a Webform. It can also link the webform submission to the node in terms of keeping the content of both of them synchronized if desired.


Top 50 recent answers are included