0

On my nodes, users won't need to make a description of their changes unless they modify the body field.

Therefore I would like to hide the revision log field on the form unless the body field (the standard CKeditor long textfield) has been changed in the form.

The standard states API approach doesn't work, because data-editor-value-is-changed is not one the permitted arguments that states API knows.

$form['revision_log']['#states'] = [
  'visible' => [
    ':textarea[name="body[0][value]"]' => [
      'data-editor-value-is-changed' => 'true'
    ],
  ],
];

The natural next attempt is to attach a jquery function to listen to changes in textarea. I can't get this to work, possibly because this textarea is being changed programatically so these events may not be firing.

(function ($, Drupal) {
    Drupal.behaviors.ahsRevisionLog = {
        attach: function (context, settings) {
            // Apply the erEnhancedRemove effect to the elements only once.
            $(context).find('textarea[name="body[0][value]"]').once('ahsRevisionLogShow').each(function () {
                console.log('Textarea has been found'); // Fires on page load
                $(this).on('input selectionchange propertychange',function(event){
                    console.log('On change event fired'); // Never fires
                    if ($this.data('editor-value-is-changed','true')){
                        console.log('Has been changed'); // Never fires
                    }
                });
            });
        }
    };
})(jQuery, Drupal);

The only other thing I can think to do is to use the onchange event defined in Drupal's ckeditor.js. But I've no idea how to do that.

  • just a confusion do you want to check if the body field is edited or the body field has value ?? – Shreya Shetty Sep 22 '16 at 5:16
  • Is edited. It only needs a revision log if it has been edited. – Jonathan Sep 22 '16 at 9:17

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.