New answers tagged

0

I prefer in this case use a single line of jQuery. $("select option:first-child").attr("disabled", "true"); It adds the disabled attribute : <option value="disabled_options" disabled="disabled">-- choice : --</option> I would have preferred to do it with formApi but I think this is too much code ...


0

I get answer here https://stackoverflow.com/a/65888182/13738862 function helper_form_views_exposed_form_alter(array &$form, FormStateInterface $form_state, $form_id) { if($form['#id']== 'views-exposed-form-pozdravleniya-taxonomy-term-page-1') { $form['sort_by']['#title'] = ''; $form['sort_by']['#options']['created'] = ''; if ($...


-1

$store_name = $form_state->getValue('name')[0]['value']; Some input files are multi-value, so you can just use getValue('field_name').


0

For this problem I think best solution is use module Webform https://www.drupal.org/project/webform, for me this is one of the best Drupal module. Also for this module you have great documentation and demo examples.


0

just got this sorted out! Decided to drill down to the array structure of the form, and found out that the #ajax element had to be attached to the widget array of the field, like this... $form['product_line']['widget']['#ajax'] = [...] Now it works. Another reason I keep crying "better documentation for Drupal"!!! How in the world was anybody ...


0

For select list, the ajax should be $form['field_select_box']['widget']['#ajax'] = [ ... ]; and please try to code as Drupal standard.


0

When you are allowed making a php file inside the template you could create a core contact form in UI and use a theme_form_alter() hook to prefill the form fields and add custom submit handlers: mytheme.theme use Drupal\Core\Form\FormStateInterface; function mytheme_form_alter(&$form, FormStateInterface $form_state, $form_id) { if ($form_id == '...


0

Think this is an OOP question... so the correct answer is to switch by the type of the instance. In PHP you do this with "instanceof", like here in MappingTest.php: protected function filterNumericFields(&$fields) { foreach ($this->view->field as $id => $field) { if (!($field instanceof NumericField)) { unset($fields[$...


0

Based on your comment, it sounds like you want a list of 9 links, and clicking a link sends the users to the node add form for the relevant content type with the Subcategory field already filled in. As you noted in your question, you can use a menu for this. The challenge is how to pre-fill the first field. For that, you can use the Prepopulate module. As ...


1

I doubt that the array you've found really assigns 2 callbacks. It's rather an array defining a class and a method for a single callback: 'callback' => ['Drupal\foo\BarClass', 'ajaxCallback'] In fact, you can only set one callback in an #ajax element. If you want to override a callback you have to include the overridden callback in your code: Drupal\foo\...


3

FormBase is abstract; it implements FormInterface, but doesn't contain methods for: getFormId buildForm submitForm You need to provide those in your class or PHP will reject it. ... class Test extends FormBase { public function getFormId() { return 'foo'; } public function buildForm(array $form, FormStateInterface $form_state) { // Build ...


0

It's hard to say what is the "best", but you can write a class, add the variables as constants, and then import the class wherever you need it. For example, in MYMODULE/src/MyVariables.php: <?php namespace Drupal\MYMODULE\SharedStuff; /** * Defines variables that need to be shared throughout the site. */ class MyVariables { // Seconds ...


1

hook_entity_extra_field_info() is invoked when either an entity is rendered, or when an entity form is shown to users. See user_entity_extra_field_info() as example. function user_entity_extra_field_info() { $fields['user']['user']['form']['account'] = [ 'label' => t('User name and password'), 'description' => t('User module account form ...


0

Just wanted to add that if you overload POST with too many form fields, exceeding your PHP max_post_size, PHP will purge POST. Since that includes submission information, no submission will occur. I had a custom form running in a loop off a database query. If it returns too many rows, the form is too large and cannot be submitted. Doesn't look like that was ...


Top 50 recent answers are included