I'm Using AngularJS, I have a need that to know whether control within the form is required or not. So that i can append the label above the control with * symbol.
I have seen solutions like below: Angularjs required asteriks
But in my case i need it for label above to it and also Not all controls are basic controls i have used plugin's like ui-select and many more.
Result:
As we have in-built isEmpty() or $dirty functions in angularjs
formName.TextBoxControlName.$dirty => true/false;
can i have function/property included in angularjs saying that isRequired (returns boolean)
formName.TextBoxControlName.$isRequired => true/false;
im expecting is it possible to have a new property to control itself like (isRequired) so that no matter what the scenario is, i can use that property for that control to set the asterisk symbol.
in HTML:
(label) {{formName.TextBoxControlName.isRequired}}
in JS:
$scope.star function (){
return $scope.formName.TextBoxControlName.isrequired ? '*' : ''
}
[Edit]
I'm Updating with Scenarios in below:
Direct Scenario
is, I have many textboxes in form with
required="textboxName" (if NOT required).
required="!textboxName" (if required).
Indirect Scenario 1:
label{*} (label)
[________] (textbox)
the input text is by default not mandatory (so NO asterisk symbol).
required="textboxName"
but on some condition i making it required (so Need asterisk symbol) as below:
$scope.formName.TextBoxControlName.$setValidity('required', false);
Indirect Scenario 2:
label{*} (label)
[________] [x] (textbox)(checkbox)
the input text is by default not mandatory (so NO asterisk symbol) But on checkbox true it is mandatory (so Need asterisk symbol).
required="checkboxName"
Now how can i maintain asterisk symbol for my scenario's in HTML page itself (if possible).