Don't allow negative number in field

When I am adding/editing a record I have a price field and I do not want to allow the user to input a negative number.

For employee price, the user should be able to leave the value blank but if they enter or select a value using the arrows they should not be able to enter/select anything less than 0.

Code:
@Html.EJS().Grid("InventoryGrid").DataSource(DataManager => { DataManager.Json(@Model.Inventory.ToArray()).InsertUrl("/Home/AddInventoryItem").UpdateUrl("/Home/UpdateInventoryItem").Adaptor("RemoteSaveAdaptor"); }).DataBound("dataBound").AllowFiltering(true).AllowMultiSorting(true).AllowSorting(true).AllowGrouping(true).AllowReordering().AllowResizing(true).AllowPdfExport().AllowExcelExport().ToolbarClick("toolbarClick").Width("auto").ShowColumnChooser(true).Columns(col =>
{
   
    col.Field("Price").HeaderText("Price").EditType("numericedit").Format("C2").Edit(new { @params = new { decimals = 2, minValue=0 } }).ClipMode(Syncfusion.EJ2.Grids.ClipMode.EllipsisWithTooltip).Width("90").Add();

    col.Field("EmployeePrice").HeaderText("Employee Price").EditType("numericedit").Edit(new { @params = new { decimals = 2, min = 0 } }).Format("C2").Width("160").Add();

    col.Field("MemberPrice").HeaderText("Member Price").Visible(false).EditType("numericedit").Edit(new { @params = new { decimals = 2} }).Format("C2").ClipMode(Syncfusion.EJ2.Grids.ClipMode.EllipsisWithTooltip).Add();
}).AllowPaging(true).ActionBegin("actionBegin").ActionComplete("actionComplete").FilterSettings(filter => { filter.Columns(filterColumns).Type(Syncfusion.EJ2.Grids.FilterType.Excel); }).SortSettings(sort => sort.Columns(sortColumns)).PageSettings(page => page.PageCount(6).PageSizes(true)).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Dialog); }).Toolbar(new List<string>() { "Add", "Edit", "ExcelExport", "PdfExport", "Search", "ColumnChooser" }).ContextMenuItems(new List<object>() { "SortAscending", "SortDescending", "Edit","Save", "Cancel", "PdfExport", "ExcelExport","FirstPage", "PrevPage", "LastPage", "NextPage" }).Render()


1 Reply 1 reply marked as answer

MS Manivel Sellamuthu Syncfusion Team February 12, 2021 06:53 AM UTC

Hi Danyelle, 

Greetings from Syncfusion support. 

We have checked your requirement and you can achieve your requirement as like using the below code example. Please refer the below code example for more information. 

<div class="pageheader"> 
 
</div> 
<div> 
@Html.EJS().Grid("InlineEditing").DataSource((IEnumerable<object>)ViewBag.dataSource).Columns(col => 
{ 
 
. . . 
    col.Field("Freight").Edit(new { @params = new Syncfusion.EJ2.Inputs.NumericTextBox() { Decimals = 2Min = 0 } }).Width("140") 
.EditType("numericedit").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); 
    col.Field("ShipCountry").HeaderText("Ship Country").Width("150").EditType("dropdownedit").Add(); 
 
}).AllowPaging().PageSettings(page => page.PageCount(2)) 
    </div> 

Please let us know, if you need further assistance. 

Regards, 
Manivel 


Marked as answer
Loader.
Up arrow icon