Search code examples
angularjsformsinputangularjs-ng-disabled

AngularJS : Does ng-disabled remove input value?


The title says everything... I've been reading several posts on Stackoverflow as well as the documentation, but I haven't found a satisfactory explanation yet.

If ng-disabled is activated, is the input value inside the tag removed?

Let me illustrate with an example.

<form method="POST" name="form" action="">
    <select ng-model="model[1]"  
            ng-options="i for i in fc.items[1]" 
            ng-disabled="true">
    </select>
    <select ng-model="model[2]" 
            ng-options="i for i in fc.items[2]" 
            ng-disabled="false">
    </select>
    <input type="submit" value="Next"/>
</form>

The input value is results[2]:number:1. (number:1 is the expected result).

When I remove ng-disabled, the result is results[1]:number:1 results[2]:number:1.

I'm about to conclude the ng-disabled affects the input value, but I'd like to know if anyone here knows how to get all the input values (if it's possible).


Solution

  • No.

    Disabling an input just make it unusable and unclickable. The value still persist.

    Your value is not send because disabled elements in a form will not be submitted.


    From W3C Input disabling:

    A disabled input element is unusable and un-clickable.

    The disabled attribute can be set to keep a user from using the element until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the element usable.

    Tip: Disabled input elements in a form will not be submitted.