Reputation: 1376
I have over 50 text box elements in page. I am trying to append minus symbol in every text box after enter value (ng-blur) by using one common javascript function. but i am unable to pass ng-model name to javascript function from jsp element ng-blur call to append minus symbol after enter value. any solution.
JSP element:
<input type="text" maxlength="10"
ng-blur="appendMinusSymbol('buzz.model1.rate')" ng-model="buzz.model1.rate"/>
<input type="text" maxlength="10"
ng-blur="appendMinusSymbol('buzz.model2.rate')" ng-model="buzz.model2.rate"/>
JS Function:
$scope.appendMinusSymbol = function(model){
// append minus symbol as prefix to ng model value
};
Note : Edited my question (model1, model2, model3 like having 50 fields)
Upvotes: 0
Views: 215
Reputation: 1841
Check my solution on this fiddle. If you can, then pass only model name like in the fiddle, otherwise you will need additional parsing. Of course you need here additional check when to append minus sign if already exists.
<input type="text" maxlength="10" ng-blur="appendMinusSymbol('model1')" ng-model="buzz.model1.rate"/>
$scope.appendMinusSymbol = function(modelName){
$scope.buzz[modelName]['rate'] = '-'+$scope.buzz[modelName]['rate'];
};
Upvotes: 1