Hello,

I wrote custom form, Using ajax_command_replace I replace some text field based on radio select, Everything works fine first loading but after first ajax call, placeholder stop working.

I try the both method using class and by set #form_placeholder true.

Comments

replicaobscura’s picture

I'd like to weigh in here.

For me the issue with AJAX submissions is that the selector does not work anymore. I am using the form ID as a selector, which is the ID of the top-level element in the "context" provided by Drupal's AJAX API. Form Placeholder then tries to select that ID within context, but it fails.

I think the solution is to select form elements in the entire document, not just within the AJAX context.

One simple way to do this, is when you set the form placeholder, append ".addClass('form-placeholder-processed')" to it.

Then above add:
exclude += ', .form-placeholder-processed';

Then remove context from the main selector. Now, it will process any unprocessed placeholders on the entire document whenever an AJAX request is recieved, allowing your selectors to include parents outside of the AJAX context.

sarav.din33’s picture

I have tried.
#form_placeholder = TRUE
But its no more help me.
For me the issue because of ajax file upload. In my form there is a ajax file upload field. Once i select & upload a file the settings variable (settings.form_placeholder) became undefined in form_placeholder.js

file: form_placeholder/form_placeholder.js
line no: 13

var include = settings.form_placeholder.include;

So i have added a typo check condition on the beginning of Placeholder attach attribute. So my script looks below,

Drupal.behaviors.form_placeholder = {
  attach: function(context, settings) {
    if(typeof(settings.form_placeholder) != 'undefined'){
      var include = settings.form_placeholder.include;
       if (include) {
        include += ', ';
       }
       **********
       **********
    }
  }
};

It will solve me the issue.

@maintainer, Please verify it.

jidrone’s picture

Status: Active » Needs review
StatusFileSize
new870 bytes

I think that the method in comment #1 is the correct, I have used it some many times with good results.

I have created a patch using that approach.

vijay.cgs’s picture

Working fine for me with the attached code #2

marcopbazz’s picture

Patch #3 worked form me!

marcopbazz’s picture

Patch #3 worked form me!

szeidler’s picture

Patch #3 is working fine for me. With that patch applied, the module is also compatible with inline_entity_form, which makes heavy use of AJAX and forms.

Yoris00’s picture

Patch #3 worked! Thx @jidrone

  • rafal.enden committed e6b6434 on 7.x-1.x authored by jidrone
    Issue #2398859 by jidrone: Not working on Ajax replace form elements
    
rafalenden’s picture

Status: Needs review » Fixed

Thank you for help!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.