Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fcsa-number is not working properly with ng-submit directive of angular #37

Open
khanstudio-github opened this issue Jul 28, 2016 · 1 comment

Comments

@khanstudio-github
Copy link

I'm submitting a ...

[x] bug report

Current behavior
Fcssa-number is not working properly with ng-submit directive. Whenever I append or prepend anything using fcsa-number and submit the form it turns that field red and stores value in model as 'undefined'. It only shows this error on append or prepend without them it works fine.

Also if I remove ng-submit and use ng-click on submit button to call saveForm() function, it works fine while using prepend/append as well. It only shows error when using ng-submit directive

This is my code from a View.html

<form id="frmCostAndApproval" name="frmCostAndApproval" ng-submit=saveForm() novalidation>
  <div class="form-group">
      <label>Workup Sum Approved:</label>
      <input type="text" fcsa-number="{ prepend: '$' , preventInvalidInput: true }" class="form-control" name="WorkupSumApproved" ng-model="costAndApprovals.WorkupSumApproved" autocomplete="off" />
  </div>
  <div class="form-group">
       <label>AG2 Total Costs Approved:</label>
       <input type="text" fcsa-number="{ preventInvalidInput: true }" class="form-control" name="AG2TotalCostApproved" ng-model="costAndApprovals.AG2TotalCostApproved" autocomplete="off" />
  </div>
<button type="submit" class="btn btn-primary" ng-disabled="frmCostAndApproval.$pristine">
                        Submit
</button>
</form>

This is my code from a angular controller file ctrl-Cost&Approval.js

$scope.saveForm = function () {
            $scope.isProcessing = true;
            var item = angular.copy($scope.costAndApprovals);
            console.log(item);
}

This is my console window output

object
 WorkupSumApproved: undefined,
 AG2TotalCostApproved: 545452

Please guide me what the issue is and provide your help to the earliest. Looking forward for a positive response. Thank you.

Expected/desired behavior
The fields with prepend/append should not be undefined when form is submitted using ng-submit directive of AngularJs

About my environment:

  • AngularJS version: v1.4.1
  • angular-fcsa-number version: v1.5.3
  • Browser: [Chrome 51.0.2704.103 m |]
@bobweil
Copy link

bobweil commented Jul 26, 2017

I just ran into this myself with ng-submit and fixed my local copy like this:

Line 120 was:
noCommasVal = viewVal.replace(/,/g, '');

I changed it to:
noCommasVal = viewVal.replace(/,/g, '').replace(options.prepend, '').replace(options.append, '');

This code is inside the function added to the $parsers collection by the directive. The idea is to remove not only the commas but also any prepend or append optional characters prior to checking validity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants