1

In my ajax callback I'm trying to change the class of a button. However, after changing the class a style attribute has been added dynamically to the button. How to avoid this:

$form['bindFields'] = array(
        '#type' => 'submit',
        '#value' => t('Save'),
        '#attributes' => ['id' => 'bindFieldsBtn','class' => ['hiddenselect']],
        '#submit' => ['::submitForm'],
    );

in my ajax callback:

$form['bindFields']['#attributes']['class'] = ['shownselect'];
        $ajax_response->addCommand(new \Drupal\Core\Ajax\ReplaceCommand('#bindFieldsBtn', $form['bindFields']));
        $ajax_response->addCommand(new InvokeCommand('#bindFieldsBtn', 'change'));

the result adding display:block which I don't need

<button id="bindFieldsBtn" class="hiddenselect button js-form-submit form-submit btn-success btn icon-before" data-drupal-selector="edit-bindfields" type="submit" name="op" value="Save" style="display: block;"><span class="icon glyphicon glyphicon-ok" aria-hidden="true"></span>

Save

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.