How can I efficiently set the error state of multiple form field after the user submits the form?
I can set the error state easily enough on a constant basis. As described in this thread I use the following HTML code:
<div class="control-group" ng-class="{ error: groupForm.textbox_Group.$invalid }">
<label class="control-label" for="textbox_Group"><i class="icon-home"></i> Organization</label>
<div class="controls controls-row">
<input type="text" class="span6" id="textbox_Group" name="textbox_Group" placeholder="Organization" ng-model="org" required>
</div>
</div>
My issue with this is that it will appear in the error state immediately on the page loading. I want it to appear normal before the user hits submit and then, only if it is $invalid
to be flagged.
I'm currently using individual flags, along the lines of:
<div class="control-group" ng-class="{ error: group.isInvalid }">
<!-- snip -->
</div>
<div class="control-group" ng-class="{ error: date.isInvalid }">
<!-- snip -->
</div>
It works, but seems very bloated to me. Is there a more streamlined way to flag any form fields in an $invalid
state, but only after that form is submitted?