I have a simple non-Ajax form that presents serialized fields for saving a whole bunch of pieces of data across multiple records i.e. a quote with multiple line items and each field on each line is editable.
The form needs to be saved before being submitted and I would love for the form’s submit button to say SAVE CHANGES (done by a URL to my quasi-controller) if the form is edited, and otherwise say SUBMIT TO CLIENT, if unedited.
I’m looking into AJAX, but am wondering if it is overkill for this situation.
Any help is appreciated.
AJAX is overkill if all you want is to change the wording on the button. If clicking ‘SAVE CHANGES’ submits the form as normal (then loads the form again with the default ‘SUBMIT TO CLIENT’?) then you won’t need it.
What you want is plain javascript. Have an onchange event handler tied to each field that changes the text of the button. It could also change other aspects of the form (such as a hidden ‘data_changed’ field) so your controller knows to save the data instead of submitting it.
If no changes occur, the button will remain as ‘SUBMIT TO CLIENT’.
Am I on track with this answer? Do you need to ‘SAVE CHANGES’ in place without submitting the form? Or would you like more details on how to achieve this?
EDIT: sample code added