0

Is it possible to add/remove form elements with clientside js? I am using ajax, but it is a bit too slow for the kind of dynamic elements I need.

3
  • Why? What is slow about Drupal Form API? Form elements need to be manipulated (add/alter/removed) with the Form API so they are part of the structure (building/rebuilding/submission).
    – Kevin
    Sep 1, 2016 at 17:04
  • It causes problems because drupal keeps the numbers of items in the field state storage.
    – Eyal
    Sep 1, 2016 at 17:20
  • You need to use the Drupal Ajax form API.
    – No Sssweat
    Sep 2, 2016 at 1:58

1 Answer 1

1

You can hide and unhide form elements with js. For example you can prepare a popup and deliver it with the main form and then trigger it in js.

You can't generate new elements, because they will be ignored when submitted.

You could build your own form solution with custom js and php code. But this is probably not the best way on the long term.

The best answer to your question, how to build dynamic form solutions, is to investigate, what you can do with a js framework and Rest API.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.