Go Back   SmartClient Forums > Technical Q&A
Wiki Register Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 30th Jun 2011, 01:34
dilip_gupta dilip_gupta is offline
Registered Developer
 
Join Date: Jun 2011
Posts: 27
Default 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
Reply With Quote
  #2  
Old 30th Jun 2011, 05:16
davidj6 davidj6 is offline
Registered Developer
 
Join Date: Jan 2008
Posts: 789
Default

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.
Reply With Quote
  #3  
Old 1st Jul 2011, 01:23
dilip_gupta dilip_gupta is offline
Registered Developer
 
Join Date: Jun 2011
Posts: 27
Default

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; 6th Jul 2011 at 07:00..
Reply With Quote
  #4  
Old 6th Jul 2011, 06:50
dilip_gupta dilip_gupta is offline
Registered Developer
 
Join Date: Jun 2011
Posts: 27
Default

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

Thanks!! in Advance

Last edited by dilip_gupta; 6th Jul 2011 at 06:59..
Reply With Quote
  #5  
Old 7th Jul 2011, 03:56
davidj6 davidj6 is offline
Registered Developer
 
Join Date: Jan 2008
Posts: 789
Default

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.
Reply With Quote
  #6  
Old 7th Jul 2011, 07:55
davidj6 davidj6 is offline
Registered Developer
 
Join Date: Jan 2008
Posts: 789
Default

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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads
Thread Thread Starter Forum Replies Last Post
ConcurrentModificationException in LoadDSTag xml-silent Technical Q&A 1 16th Jan 2011 18:32
Problem during evaluation re: updating joined data peterunivex Smart GWT Technical Q&A 16 11th Jan 2011 09:06
Upload / Download DMI kfang Smart GWT Technical Q&A 12 7th Dec 2010 13:38
Conditional validation Diether Technical Q&A 5 3rd Dec 2008 12:45
server side conditional required validation CUE_TheZenith Technical Q&A 1 10th Dec 2007 11:19

© 2010,2011 Isomorphic Software. All Rights Reserved