Jaume
Jaume

Reputation: 63

Change field value with javascript on submit

I need to execute something like this in a CRUD form (simplified example):

$crud->form->js('submit',$crud->form->getElement('data')->js()->val('My text'));

I need to change data field before submit. The event is executed but field is not updated. I guess POST values are already assigned when this event is fired.

data is a textarea hidden by a TinyMCE component I'm trying to integrate as an addon. All works ok but when form is sent via ajax you need to manually update textarea from TinyMCE content. I've tested a lot of ways, including "raw" javascript (js("submit","document.getElementById(...)") but no luck until now.

Do you know how can I have this field changed before submitting?.

Thanks!!

Upvotes: 2

Views: 246

Answers (1)

Jaume
Jaume

Reputation: 63

Solved adding this.form.trigger('beforesubmit') in ui.atk4-form.js before form data serialization.

Then you can add in your code:

$form->js('beforesubmit', ...
  //Changes to fields done here are submitted because form fields are still not processed.
)

Upvotes: 1

Related Questions