Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Conditional validation

    I have a problem in conditional validation, I have a drop down and a text box and on text box I have to validate based on the value selected in drop down. Like I have some value to be selected from drop down as email, phone number,username etc. and If user selected email from drop down then on text field I need to perform email validation and if user selected username then I need to perform username validation on text box.
    Can any one give me any suggestion how to achieve such requirement in smartclient.

    Using smartclient 8

    #2
    You are looking for something like:
    Code:
    validators: [
        { type: "readOnly", fieldAppearance: "hidden", validateOnChange: true,
            applyWhen: {fieldName: "FieldType", operator: "equals", value: "email" }
        }
    ]
    Although this is a field appearance validator you can use any validator type and just specify when it should be applied. Just add as many validators as you need based on your selections.

    Comment


      #3
      Hi David,
      Thanks for your quick response.. I am looking for something like you provided But the problem what I am facing that my validation doesn't look for the condition which I am providing. Like I would like to perform email validation on text only if user has selected email (from drop down). And facing same problem when I use your code also, as below

      Code:
      this.actionListGrid = isc.ListGrid.create({
          ID: "actionListGrid",height:"100%",width:"100%",stopOnErrors:true,
          alternateRecordStyles:true, showEdges:false,canHover:true,
          fixedRecordHeights: false,wrapCells:false,border:"1px solid #cccccc",
          canReorderFields: false,autoFetchData: false,validateByCell:true,
      
      fields:[
      	{name:"aname",title:"Action To Perform",width:"50%", editorType:"comboBox",valueMap:actionsJSON},
      		{name:"avalue",title:"Value(Optional)",width:"40%"
      		,validators:[{
      			type: "invalidNumberOrEmailCheck",
      			validateOnChange: true,
      			fieldAppearance: "hidden",
                       //expression: "actionListGrid.getCellValue('aname')=\"FORWARD_MESSAGE\"",
      			applyWhen: {fieldName: "aname", operator: "equals", value: "FORWARD_MESSAGE" },
      
                  errorMessage: "Please provide a valid Email or US Number as value"
      		}
      		 ]
      and actionsJSON I have

      Code:
      actionsJSON = {"FORWARD_MESSAGE":"Forward to Email/Number","MOVE_MESSAGE":"Move to Trash", "REPLY_MESSAGE":"Auto reply", "PB_POST":"Post to Portal","PB_STATUS_UPDATE":"Portal status update","PB_NOTE":"Post a note to Portal"};
      and Custom Validator named "invalidNumberOrEmailCheck"

      Problem with this is when user selects Auto Reply then also validation of email/Number gets performed But I need to perform another validation.
      Last edited by dilip_gupta; 6 Jul 2011, 07:00.

      Comment


        #4
        Can any one give any suggestion/Idea how to achieve such Requirement using custom validation

        Thanks!! in Advance
        Last edited by dilip_gupta; 6 Jul 2011, 06:59.

        Comment


          #5
          That solution should work and it does in forms but not in a grid because the applyWhen check is run against the previously stored record values, if any, instead of the edit values. This is based on a quick glance at the code and not actual testing. Note also that if you setup one or more validators on a field with an applyWhen "equals" condition it should actually fail to run any of the validators for a new grid record.

          In your example there should be one validator per selectable action and the applyWhen determines which validator(s) should be processed.

          Comment


            #6
            I have actually tested this scenario with the latest SC nightly and I am able to conditionally apply validators in a ListGrid row (editByRow) successfully. I just modified the Feature Explorer massUpdate sample by adding a conditional validator to the population column based on the continent.
            Code:
                    {name:"population", 
                     formatCellValue:"isc.Format.toUSString(parseInt(value))",
                       validators: [
                           { type: "integerRange", validateOnChange: true, max: 100000,
                             applyWhen: {fieldName: "continent", operator: "equals", value: "Asia" }
                           }
                       ]},
            If you continue to be unable to make this work properly with the latest nightly, please post a small, standalone sample that shows your problem.

            Comment

            Working...
            X