Announcement

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

    Using data mask and formatter on a text item

    Hello,

    We have a case where we want to use a certain data mask as well as a formatter to have a mask to assist input and to have a different format for viewing. It seems that once a mask is specified the format(ter) is ignored.

    Is this intended behavior and if so, can we 'disable' that feature somehow?

    With this sample code you can see that the formatter is ignored:

    Code:
            DynamicForm form = new DynamicForm();  
            form.setWidth(400);  
    
            TextItem percentageField = new TextItem("percentageItem", "Percentage");  
            percentageField.setMask("999\\%");  
            percentageField.setValue(200d);
            percentageField.setEditorValueFormatter(new FormItemValueFormatter() {
    			
    			public String formatValue(Object value, Record record, DynamicForm form, FormItem item) {
    				return "111";
    				
    			}
    		});
              
            form.setFields(percentageField);
    We are not certain but we recall that this used to work on an earlier version.
    It seems logical that the mask is only used for editing, not for display purpose.
    Please advise.

    We are on SNAPSHOT_v8.3d_2012-08-14/Pro Deployment (built 2012-08-14).
    thanks

    #2
    You are specifically using setEditorValueFormatter(), which formats the value *during editing* - this doesn't make sense with masking, but setValueFormatter() does.

    Comment


      #3
      Ok, I understand. We have a similar case when we add simple types to the mix. This is a reduced sample of our approach there which leads to the same behavior. Could you also please suggest how we can get the format applied there as well.

      Code:
      	private class MyType extends SimpleType {
      		
      		public MyType() {
      			
      			super("mine", FieldType.ANY);
      			
      			SimpleTypeFormatter formatter = new SimpleTypeFormatter() {
      				
      				public String format(Object value, DataClass field, DataBoundComponent component, Record record) {
      					return "111";
      				}
      			};
      			
      			setNormalDisplayFormatter(formatter);
      			setShortDisplayFormatter(formatter);
      			setEditFormatter(formatter);
      		}
      	}
      	
      	@Override
      	public Canvas getViewPanel() {
      		
      		new MyType().register();
      		
              DynamicForm form = new DynamicForm();  
              form.setWidth(400);
      
              TextItem percentageField = new TextItem("percentageItem", "Percentage");
              percentageField.setAttribute("type", "mine");
              percentageField.setMask("999\\%");
              percentageField.setValue(200d);
                
              form.setFields(percentageField);  
        
              return form;
      	}
      many thanks

      Comment


        #4
        This appears to be the same scenario, and as expected, formatting is not applied to values being edited with a mask (since this does not make sense).

        Comment


          #5
          That's clear, thanks.

          Comment


            #6
            SmartGWT 2.5.1 - GWT 4.0 / Eclipse Version: Indigo Service Release 2 / Firefox 21.0 OR Google Chrome Version 28.0.1500.52
            ----------------------------

            Hello,

            I have a similar case, where:
            STEP 1
            in a column, say TimeInterval, I get an Integer (433), which corresponds to the number of seconds of the Time interval. This value is displayed in the ListGridField like this:
            e.g. 7min 13sec.

            STEP 2
            in the respective filter, I have added a textItem with the following mask: "##y ##m ##w ##d ##h ##min ##sec", thus the user only needs to write the desired hours, minutes etc. in that txtItem (no need to add literals like min, sec etc.).

            STEP 3
            In order to correctly interpret user input into integer (=seconds), I have implemented a setEditorValueParser() on the textItem. The filter works fine (=correct values are fetched with criteria)

            PROBLEM in STEP 4
            When user opens filter again, I have found no way to display the processed (masked) value. The initial value of the field is the Integer (seconds), but the mask fails to be correctly applied.


            QUESTION
            Why do you say that setEditorValueFormatter() doesn't have meaning with a masked TextItem?
            I mean, since the user needs to have a mask (since it's gonna be difficult to remember this format ##y ##m ##w ##d ##h ##min ##sec) isn't there a point in having both mask and setEditorValueFormatter() working?

            Comment

            Working...
            X