简体   繁体   中英

In angularjs how to submit a form with disabled fields

I have a form in angularjs which have certain input text fields and a checkbox. If the checkbox is selected then it will disable some certain fields in the form but the value will remain visible, so that, if user deselected the checkbox then, he doesn't have to fill those fields again. However, I don't want to submit the values of the disabled fields when user submits the form.

I'll list 3 ways, by the order i would suggest:

  1. submit it whole, and disregard the excessive data Server Side.
    i assume the "disabled" data is not too big to affect performance.

  2. process the form data before submission.
    run Javascript onSubmit() $(form).find('input[disabled]').value(null);
    (hope my jQuery syntax is correct.)

  3. least recommended, instead of just disable the inputs, you can set input.placeholder = input.value; input.value = ''; input.placeholder = input.value; input.value = ''; and the opposite when you re-enable it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM