1

I am using Drupal Commerce. For the Variations, I am using multiple add /remove via AJAX.

I need to make field readonly.

0 -> <input type="number" name="variations[form][inline_entity_form][entities][0][form][field_stock][0][value]" value="0" step="1" placeholder="" class="form-number" />

1 -> <input type="number" name="variations[form][inline_entity_form][entities][1][form][field_stock][0][value]" value="0" step="1" placeholder="" class="form-number" />

I have given example with 2 variations. How can I achieve it via form_alter ?

On Add of variation I need to unset that field and at the edit time need to make readonly.

Already checked with hook_inline_entity_form_entity_form_alter() but it is not going there.

  • Take a look at this drupal.org/project/inline_entity_form/issues/… i think you should add #after_build in your hook_form_alter and add your logic in the after_build callback – berramou Nov 20 '19 at 11:19
  • Thanks @berramou. Yes it's going in to #after_build. But I am still not able to get that field which needed. – Ankit Shah Nov 21 '19 at 1:54
  • if #afterbuild does not work do it with Javascript eg attach a library with in the cart then $('input[name^="variations[form][inline_entity_form][entities]"]' ) ... do the stuff – Taggart Jensen Nov 21 '19 at 4:45
  • Hi @TaggartJensen Yes right now able to manage via JS. It would be great it able to manage via Drupal level from alter. – Ankit Shah Nov 21 '19 at 4:49

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.