Announcement

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

    SelectItem bug with long option names

    If you select an item like ADVRT/JLMC 101 Hamilton for the delivery option and Submit, it will give a validation error. Selecting a shorter name won't. Also the full length of the item is not displayed correctly in the selectitem box.
    Code:
    package edu.iastate.its.thinkspace.test.client.test;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.core.KeyIdentifier;
    import com.smartgwt.client.data.DataSourceField;
    import com.smartgwt.client.data.RestDataSource;
    import com.smartgwt.client.types.Alignment;
    import com.smartgwt.client.types.DSDataFormat;
    import com.smartgwt.client.types.FieldType;
    import com.smartgwt.client.util.KeyCallback;
    import com.smartgwt.client.util.Page;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.BlurbItem;
    import com.smartgwt.client.widgets.form.fields.ButtonItem;
    import com.smartgwt.client.widgets.form.fields.DateItem;
    import com.smartgwt.client.widgets.form.fields.FormItem;
    import com.smartgwt.client.widgets.form.fields.SelectItem;
    import com.smartgwt.client.widgets.form.fields.SpacerItem;
    import com.smartgwt.client.widgets.form.fields.TextAreaItem;
    import com.smartgwt.client.widgets.form.fields.TextItem;
    import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
    import com.smartgwt.client.widgets.form.fields.events.ClickHandler;
    import com.smartgwt.client.widgets.form.validator.DoesntContainValidator;
    import com.smartgwt.client.widgets.layout.VStack;
    
    public class Test implements EntryPoint {
    
        public void onModuleLoad() {
    	    KeyIdentifier debugKey = new KeyIdentifier();
    	    debugKey.setCtrlKey(true);
    	    debugKey.setKeyName("D");
    
    	    Page.registerKey(debugKey, new KeyCallback() {
    	        public void execute(String keyName) {
    	            SC.showConsole();
    	        }
    	    });
    	    VStack stack = new VStack();
    	    stack.setWidth100();
    	    stack.setPadding(10);
    	    stack.setDefaultLayoutAlign(Alignment.CENTER);
    	    stack.addMember(getTESForm());
    	    stack.draw();
        }
    
    	private DynamicForm getTESForm() {
    		final DynamicForm form = new DynamicForm();
    		form.setWidth(600);
    		form.setHeight100();
    		form.setNumCols(8);
    		form.setBackgroundColor("#DBEAFE");
    		form.setAutoFetchData(true);
    		TextItem name = new TextItem("name", "Name");
    		name.setStartRow(true);
    		name.setColSpan(8);
    		name.setWidth(200);
    		name.setDefaultValue("test");
    		TextItem phone = new TextItem("phone", "*Phone Number");
    		phone.setStartRow(true);
    		phone.setColSpan(8);
    		phone.setWidth(60);
    		phone.setDefaultValue("2-0000");
    		TextItem section = new TextItem("section", "Section");
    		section.setStartRow(true);
    		section.setColSpan(8);
    		section.setDefaultValue("test");
    		section.setWidth(250);
    		DateItem dropoff = new DateItem("dropoff", "Drop-off Date");
    		dropoff.setStartRow(true);
    		dropoff.setColSpan(8);
    		SelectItem delivery = new SelectItem("delivery", "* Delivery Location");
    		delivery.setWidth(300);
    		delivery.setStartRow(true);
    		delivery.setDefaultToFirstOption(true);
    		delivery.setColSpan(8);
    		setValueMap(delivery);
    		TextItem column = new TextItem("column","*Column Name");
    		column.setStartRow(true);
    		column.setColSpan(8);
    		column.setDefaultValue("column");
    		column.setHint("case-sensitive");
    		TextItem exam = new TextItem("exam", "<b>Exam#</b>");
    		exam.setStartRow(true);
    		exam.setWidth(30);
    		TextItem quiz = new TextItem("quiz", "<b>Quiz#</b>");
    		quiz.setStartRow(false);
    		quiz.setWidth(30);
    		FormItem midterm = new TextItem("midterm", "<b>Midterm#</b>");
    		midterm.setStartRow(false);
    		midterm.setWidth(30);
    		TextItem finalnum = new TextItem("finalnum", "<b>Final#</b>");
    		finalnum.setWidth(30);
    		finalnum.setStartRow(false);
    		TextItem email = new TextItem("email", "*Email List");
    		email.setWidth(250);
    		email.setStartRow(true);
    		email.setColSpan(8);
    		email.setLength(255);
    		email.setDefaultValue("george@bogus.com");
    		email.setHint("<nobr>comma-separated</nobr>");
    		TextItem code = new TextItem("code", "<nobr><b>Special Code Column Name</b></nobr>");
    		code.setStartRow(true);
    		code.setColSpan(8);
    		TextAreaItem inst = new TextAreaItem("inst", "<nobr><b>Special Instructions</b></nobr>");
    		inst.setColSpan(8);
    		inst.setStartRow(true);
    		inst.setWidth(250);
    		inst.setLength(1000);
    		ButtonItem submit = new ButtonItem("Submit");
    		submit.setStartRow(false);
    		submit.addClickHandler(new ClickHandler() {
    			@Override
    			public void onClick(ClickEvent event) {
    				if (form.validate()) {
    					form.submit();
    				}
    			}			
    		});
    		form.setIsGroup(true);
    		form.setGroupTitle("Test and Evaluation Submission Form");
    		SpacerItem spacer = new SpacerItem();
    		spacer.setStartRow(true);
    		form.setDataSource(getTESDS());
    		form.setItems(name,section,phone,dropoff,delivery,column,exam,quiz,midterm,finalnum,email,code,inst,spacer,submit);
    		return form;
    	}
    
    	private void setValueMap(SelectItem item) {
    		item.setValueMap("Select Location",	
    				"Durham 195 Durham",	
    				"ADVRT/JLMC 101 Hamilton",	
    				"AERO E  1200 Howe", 	
    				"AESHM   31 Mackay",	
    				"AGEDS  201 Curtiss",	
    				"AGRON   1125 Agron",	
    				"AN S   119 Kildee",	
    				"ANTHR/SOC   103 East Hall",	
    				"BBMB/GDBC   1210 Molecular Biol",	
    				"BUSINESS   2200 Gerdin",	
    				"C B E   2162 Sweeney",	
    				"C I/SP ED   N137 L'marcino",	
    				"CCE E   394 Town",	
    				"CHEM  1608 Gilman",	
    				"Com S   226 Atanasoff",	
    				"DSGN  134 Design",	
    				"E E/CPR E  2205 Coover",	
    				"ECON   174 Heady",	
    				"EEOB   253 Bessey",	
    				"ELPS    N243 L'marcino",	
    				"ENGL   203 Ross",	
    				"ENT   110 Insectary",	
    				"FSHN   220 MacKay",	
    				"GEOL/MTEOR  253 Sci I",	
    				"HD FS   2330 Palmer",	
    				"HIST    603 Ross",	
    				"HONORS   2130 Jischke",	
    				"HORT  160 Hort",	
    				"IMSE  3004 Black",	
    				"ISBR 2625 N Loop Blgd2 S2500", 	
    				"ISU DINING  1215 Friely",	
    				"KIN/H S/EX SP   235 Forker",	
    				"LAS   309 Catt", 	
    				"LIB   140 Library",
    				"M E     2025 Black Engr",
    				"M S E   2220 Hoover",
    				"MATH   396 Carver",
    				"MICRO  207 Sci I",
    				"MUSIC  149 Music",
    				"NREM  124 Sci II",
    				"PHIL/RELIG  402 Catt",
    				"PHYS   12 Physics",
    				"POL S    503 ROSS",
    				"PSYCH  W112 L'marcino",
    				"SOC  103 East Hall",
    				"SP CM/COM ST   308 Carver",
    				"STAT      1121 Snedecor",
    				"STD COUN SVC  2223 SSB 3rd Flr",
    				"THTRE  210 Pearson",
    				"VET MED   2270 Vet Med",
    				"W S     208 Carve",
    				"WLC   3102 Pearson");
    	}
    	private RestDataSource getTESDS() {
    		RestDataSource ds = new RestDataSource();
    		ds.setDataURL("/webapps/ISU-admintools-bb_bb60/admintools");
    		ds.setDataFormat(DSDataFormat.XML);
    		Map<String,String> map = new HashMap<String,String>();
    		map.put("courseId", "");
    		map.put("tool", "tes");
    		map.put("option", "data");
    		ds.setDefaultParams(map);
    		DataSourceField name = new DataSourceField("name", FieldType.TEXT, "Name", 20, true);
    		name.setPrimaryKey(true);
    		DataSourceField phone = new DataSourceField("phone", FieldType.TEXT, "Phone Number", 10, true);
    		DataSourceField section = new DataSourceField("section", FieldType.TEXT, "Section", 20, true);
    		DataSourceField dropoff = new DataSourceField("dropoff", FieldType.DATE, "Drop-off Date", 20, true);
    		DataSourceField delivery = new DataSourceField("delivery", FieldType.ENUM, "Delivery Location", 20, true);
    		DataSourceField column = new DataSourceField("column", FieldType.TEXT, "Column Name", 20, true);
    		DataSourceField exam = new DataSourceField("exam", FieldType.TEXT, "Exam#", 4, false);
    		DataSourceField quiz = new DataSourceField("quiz", FieldType.TEXT, "Quiz#", 4, false);
    		DataSourceField midterm = new DataSourceField("midterm", FieldType.TEXT, "Midterm Exam#", 4, false);
    		DataSourceField finalnum = new DataSourceField("finalnum", FieldType.TEXT, "Final Exam#", 4, false);
    		DataSourceField email = new DataSourceField("email", FieldType.TEXT, "Email List", 50, true);
    		DataSourceField code = new DataSourceField("code", FieldType.TEXT, "Special Code Column Name", 20, false);
    		DataSourceField inst = new DataSourceField("inst", FieldType.TEXT, "Special Instructions", 20, false);
    		ds.setRecordXPath("//tes");
    		ds.setFields(name,section,phone,dropoff,delivery,column,exam,quiz,midterm,finalnum,email,code,inst);
    		return ds;
    	}
    	
    }
    The datasource data:
    Code:
    <response>
    	<status>0</status>
    	<data>
    	  <tes>
    		<name>test</name>
    		<section>test</section>
    		<phone>2-0000</phone>
    		<email>george@bogus.com</email>
    		<delivery>Select Location</delivery>
    	  </tes>
    	</data>
    </response>
    SmartClient Version: SC_SNAPSHOT-2010-12-03/LGPL Development Only (built 2010-12-03)
    GWT2.0.4
    Firefox

    #2
    You have specified a length of 20 for the DataSourceField "delivery" field so upon selection the value gets truncated to 20 characters and this does not match the value in the value map. Increase the value of the length appropriately.

    DataSourceField delivery = new DataSourceField("delivery", FieldType.ENUM, "Delivery Location", 20, true);

    Comment


      #3
      So obvious. Thanks.

      Comment

      Working...
      X