1

I am using ui-grid v3.0.0-rc.22 in my apllication. I enabled edit feature using ui-grid-edit.

i use following in columnDefs

{displayName: 'Price', field: 'price', type: 'number', width: 70, aggregationType: uiGridConstants.aggregationTypes.sum, },

How can i stop to insert negative value in this

Any help greatly appreciated.

4
  • Please provide a plunker or jsfiddle project. I'm trying to see where you want the negative value to be input... Can you reword "How can i stop to insert negative value in this". Commented Jul 15, 2015 at 5:04
  • I trying say is : No one can insert negative value in price field. Commented Jul 15, 2015 at 5:18
  • Add an ng-model to the price column and add validation in your controller. Commented Jul 15, 2015 at 5:32
  • @BrianGerhards i try this plnkr.co/edit/SMRtoKgEtlP6th6IVXCp?p=preview but not working Commented Jul 15, 2015 at 6:00

2 Answers 2

4

In Ui-Grid, the editors are rendered using the ui-grid/cellEditor template. The default template does not have any validation as part of it. To add the validation, you can provide your own editableCellTemplate and provide min value to achieve your requirement.

editableCellTemplate :"<div><form name=\"inputForm\"><input type=\"INPUT_TYPE\" ng-class=\"'colt' + col.uid\" ui-grid-editor ng-model=\"MODEL_COL_FIELD\" min=\"0\"></form></div>"

This is just a copy of the default template but with the min="0" added to avoid the negative numbers.

Look here for working sample ...

http://plnkr.co/edit/cHhiXYKflQMvnOI2C5lj?p=preview

Sign up to request clarification or add additional context in comments.

Comments

0

simplest thing will be make input type="number" and min="0"

another way would be place and ng-model in the input and validate its values with ng-change.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.