Currently, I am developing a dynamic form using Angular (1.3b17). In my approach, I store the form's schema in an object with various properties defining field behavior like "type" (text, textarea, check, etc) and "maxlength." Subsequently, I assign these properties to angular attributes for the elements based on the corresponding object values (e.g., ng-maxlength="field.maxlength").
An interesting observation came to light which led me to question if this is by design. When I set the attribute without specifying a value (ng-maxlength=""), $error immediately turns true after typing anything as it assumes a maximum length of 0. The same behavior occurs when using an expression (ng-maxlength="field.maxlength") when the property is not defined.
I have provided a simple Plunker for reference. My expectation was that there should be no maxlength checks if the value is not set, even when the attribute is present.
<input id="txtName" ng-model="myval" type="text" name="name" ng-maxlength="" /><br />
{{myForm.name.$error}}
Alternatively,
<input id="txtName" ng-model="myval" type="text" name="name" ng-maxlength="someundefinedvalue" /><br />
{{myForm.name.$error}}
While I could workaround this by setting ng-maxlength to a large value, it does not seem like an ideal solution. Is there a specific rationale for this behavior, or could it possibly be a bug?