Announcement

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

    How to get display value for a select item in a ListGridRecord

    I have a ListGridField which has an optionDataSource and is rendered as a SelectItem in an editable ListGrid. I have added an EditorExitEvent to make sure that their selection is not a duplicate of the selection in another row of the grid. If it is a duplicate I show a message and cancel the EditorExitEvent to force them to make another selection. All of that seems to work fine, but I would like to get the display value for the currently selected row in the SelectItem. I don't see any way to access the FormItem that is being exited. Is there a way?

    If there is a better way to do this than EditorExitEvent please let me know. The basic requirement is to prevent multiple ListGridRecords from being created with the same value in this field (the SelectItem).
    Last edited by jay.l.fisher; 3 Nov 2010, 12:06.

    #2
    I think there must be a better way than using EditorExitEvent. That works OK if I tab away from the SelectItem, but if I click the cursor somewhere outside of the SelectItem I get stuck in an event loop where the pop-up I'm showing reappears right after being dismissed. Here is my code.
    Code:
    // Don't allow duplicate colors in the list.
    iclr.addEditorExitHandler(new EditorExitHandler() {				
    	@Override
    	public void onEditorExit(EditorExitEvent event) {
    		for (int rowNum=0; rowNum<event.getGrid().getRecords().length; rowNum++) {
    			String iclr = event.getGrid().getRecord(rowNum).getAttribute(ICLR);
    			if (iclr==null) 
    				iclr="";
    			if (rowNum!=event.getRowNum()
    					&& iclr.equals(event.getNewValue().toString())) {
    				event.cancel();
    				SC.warn("Color " + event.getNewValue() + " is already in the list.");
    				return;
    			}
    		}	
    	}
    });
    I've tried moving the event.cancel() after the SC.warn and that doesn't seem to make any difference.

    Comment


      #3
      Ah - yes - showing the modal dialog would take focus from the editor, which itself would trip the editor exit handler and could potentially lead to this kind of thing.

      When exactly do you want the user to be notified, and are you wedded to a pop up dialog?
      A couple of possibilities that come to mind:

      - You could specify a change handler on the editorProperties for the field in question which shows the dialog / cancels the change if the uniqueness requirement is not met. This would then fire when the user selected a new value from the select box if it wasn't valid.

      - You could specify a custom validator on the field, with a condition that ran the uniqueness check. This would run by default when the user attempted to save the row (though validateByCell could be set to force per-cell validation). The error would be displayed using the standard 'validation failure' icon rather than in a dialog if you took this approach.

      Comment


        #4
        I'd actually prefer the validator approach and went that direction initially, but I don't see how to determine the gird and row in that context. How can you tell what grid row is being validated from within the condition() method?

        Comment


          #5
          I'm trying the change handler option but I don't see any way to cancel the event. I'm using ListGridField.addChangeHandler but com.smartgwt.client.widgets.grid.events.ChangeEvent doesn't have a cancel() method.

          When you say "a change handler on the editorProperties for the field" what exactly do you mean. I don't see a ListGridField.setEditorProperties() method either.

          Comment


            #6
            'setEditorType()' not 'setEditorProperties()' - sorry for the confusion.

            This should allow you to specify a formItem to act as a set of "template" properties for the items created to edit values in the ListGridField.

            Comment


              #7
              A couple of follow ups on this:

              The ListGridField level change event should be cancellable. We're going to make that change today.

              In terms of taking the approach of using a custom validator, assuming that the validator is basically specific to the ListGrid, you could declare it as a final variable and defined the validator in the same scope, or store a reference to it directly on the validator object via 'setAttribute'.
              Once you have the listGrid, you can determine the current editRow via "getEditRow()" and work from there.

              Comment

              Working...
              X