I have created a numberDirective
function numberInputDirective()
{
return
{
restrict: 'E',
scope:
{
model: '=',
disabled: '=?',
decimals: '=?',
form: '=',
name: '='
},
require: '^form',
replace: true,
templateUrl: 'directives/pxNumberInput.html',
link: function (scope, element, attrs, form)
{
scope.inError = function ()
{
return form.control.$valid; //I need to do something like this
}
}
}
I need to check in the isError function if the value in the control is valid or not
The template is:
<input class="input-field form-control" type="number" ng-model="model">
The HTML is:
<form role="form" class="form-horizontal psi-keyrates-yieldform psi-keyrates-historical-topcurves" name="SampleControlsForm" novalidate>
<px-number-input id="objectiveid" name="numericExample" model="sampleDataModel.numericField" placeholder="Enter numeric value" label="Numeric" required maxlength="10"></px-number-input>
</form>
While the form variable tells me if the form (form.$valid) is valid or not, I need to know this particular directive has a valid value or not when the form is submitted. something like this form.control.$valid.
I do not know the name of the control in this directive as it will be set in the html.
I tried: var elem = ctrl.$name + '.' + element.attr('name') + '.$valid'; This returns the string "SampleControlsForm.numericExample.$valid" and if I add a watch on it, it doesn't help nor does scope.$eval.
I'm sure I'm not using it right.