Conditional Validation on Column(s)

2 posts, 0 answers
  1. technotes
    technotes avatar
    9 posts
    Member since:
    Jan 2013

    Posted 17 Sep 2015 Link to this post

    I would like to setup a validation rule that would conditionally be applied.  For example

    I have three fields

    Status:  Enum field (​pending, approved, denied)
    Denied Code: (price, qty, misc..., ect...)
    Comment (Long text)


    So if the Status is equal to denied I want the Denied Code and Comment to require an update otherwise ignore them.  Is this possible? and if so how would I go about doing this?  Also the value of the Denied Code must not equal none. 

     My Index page:

        .cont {
      padding-right: 10%;
      padding-left: 10%;
      margin-right: auto;
      margin-left: auto;
    <div class="cont">
        .Columns(columns =>
            columns.Bound(c => c.PurchId).Title("Order Id").Width(120);
            columns.Bound(c => c.LineNum).Title("Line").Width(80).Hidden(true).IncludeInMenu(true);
            columns.Bound(c => c.ItemId).Width(120);
            columns.Bound(c => c.ExternalItemId).Title("External Id").Width(120);
            columns.Bound(c => c.Name).Width(400);
            columns.Bound(c => c.DeliveryDate).Width(140).Format("{0:MM/dd/yy}");
            columns.Bound(c => c.PurchUnit).Width(75).Title("Unit");
            columns.Bound(c => c.Quantity).Width(120).Format("{0:#,##0}");
            columns.Bound(c => c.PurchasePrice).Width(100).Title("Price").Format("{0:$ #,##0.00}");
            columns.Bound(c => c.LineAmount).Width(160).Hidden(true).IncludeInMenu(true).Format("{0:$ #,##0.00}");
            columns.Bound(c => c.LineDiscount).Width(80).Hidden(true).IncludeInMenu(true);
            columns.Bound(c => c.LinePercent).Width(80).Hidden(true).IncludeInMenu(true);
            columns.Bound(c => c.ApprovalStatus).Width(130).EditorTemplateName("ApprovalStatusEditor").Title("Status");
            columns.ForeignKey(c => c.ApprovalReasonId, (System.Collections.IEnumerable)ViewData["ApprovalReason"], "Id", "Description").Width(350).Title("Denied Code");
        .ToolBar(toolbar =>
        .Editable(editable => editable.Mode(GridEditMode.InCell))
        .Pageable(p => p.PageSizes(true).PageSizes(new int[] {20,50,100,1000}))
        .Filterable(filtering => filtering.Enabled(true))
        .Sortable(s => {
        .Scrollable(scrollable => {
        .DataSource(dataSource => dataSource
            .Model(model => {
                model.Id(p => p.CompanyId);
                model.Field(c => c.PurchId).Editable(false);
                model.Field(c => c.LineNum).Editable(false);
                model.Field(c => c.ItemId).Editable(false);
                model.Field(c => c.ExternalItemId).Editable(false);
                model.Field(c => c.Name).Editable(false);
                model.Field(c => c.CurrencyCode).Editable(false);
                model.Field(c => c.PriceUnit).Editable(false);
                model.Field(c => c.Quantity).Editable(false);
                model.Field(c => c.PurchUnit).Editable(false);
                model.Field(c => c.PurchasePrice).Editable(false);
                model.Field(c => c.DeliveryDate).Editable(false);
                model.Field(c => c.LineAmount).Editable(false);
                model.Field(c => c.LineDiscount).Editable(false);
                model.Field(c => c.LinePercent).Editable(false);
            .Read(read => read.Action("PurchaseJournalTransactions_Read", "Approval"))
            .Update(update => update.Action("PurchaseJournalTransactions_Update", "Approval"))
        <br />

  2. Petyo
    Petyo avatar
    2444 posts

    Posted 21 Sep 2015 Link to this post



    the custom validation approach is not limited to the field in question - you may use jQuery to check the state of the other form elements, too. Please check this demo as a starting point.


    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top