Announcement

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

    Enhancement: RegExpValidator modifiers (client and server)

    Hi Isomorphic,

    I have a usecase (current 5.0p) where I want to disallow a specific value used for internal matters to be entered in the UI and saved to the DB.

    This value is case-insensitive. As it is just one value I can use the approach you showed here.

    But in general support for RegExp modifiers (client and server, most likely realised differently) would be nice.

    See this client-only example and the screenshot:
    Code:
    package com.smartgwt.sample.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.core.KeyIdentifier;
    import com.smartgwt.client.util.PageKeyHandler;
    import com.smartgwt.client.util.Page;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.TextItem;
    import com.smartgwt.client.widgets.form.validator.RegExpValidator;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class BuiltInDS implements EntryPoint {
    	private VLayout vL;
    	private TestForm tF;
    
    	public void onModuleLoad() {
    		KeyIdentifier debugKey = new KeyIdentifier();
    		debugKey.setCtrlKey(true);
    		debugKey.setKeyName("D");
    
    		Page.registerKey(debugKey, new PageKeyHandler() {
    			public void execute(String keyName) {
    				SC.showConsole();
    			}
    		});
    
    		vL = new VLayout(5);
    		vL.setPadding(20);
    		vL.setWidth100();
    		vL.setHeight100();
    		tF = new TestForm();
    
    		IButton validate = new IButton("Validate");
    		validate.addClickHandler(new ClickHandler() {
    			@Override
    			public void onClick(ClickEvent event) {
    				tF.validate();
    			}
    		});
    
    		IButton reload = new IButton("Reload");
    		reload.addClickHandler(new ClickHandler() {
    			@Override
    			public void onClick(ClickEvent event) {
    				vL.removeChild(tF);
    				tF.markForDestroy();
    				tF = new TestForm();
    				vL.addMember(tF, 0);
    			}
    		});
    		vL.addMembers(tF, validate, reload);
    		vL.draw();
    	}
    
    	private class TestForm extends DynamicForm {
    		public TestForm() {
    			super();
    			TextItem tI1 = new TextItem("tI1");
    			tI1.setValidators(new RegExpValidator("/^(?!test$)/i"));
    			TextItem tI2 = new TextItem("tI2");
    			tI2.setValidators(new RegExpValidator("^(?!test$)"));
    			TextItem tI3 = new TextItem("tI3");
    			tI3.setValidators(new RegExpValidator("^(?![tT][eE][sS][tT]$)"));
    			setFields(tI1, tI2, tI3);
    		}
    	}
    }
    I do not know what exactly happens with the first validator, it seems to reject any value, although I think it should work with respect to the Mozilla JavaScript docs (I'm testing in FF26 dev mode). This might be a bug (not necessarily in your product), but not an important one as the same validator applied in a .ds.xml-file would definitely not work on the server side because of the different syntax.

    So for the enhancement you would need a different RegExpValidator constructor taking also the modifiers and apply them accordingly to each implementation on the client and on the server.

    As I can work around this need with character sets this enhancement has no priority for me.

    Best regards
    Blama
    Attached Files

    #2
    Noted: you'd like to see support for regexp modifiers.

    Your first regex doesn't work because you are trying to embed delimter characters from a JavaScript regex literal in the expression itself ("/").

    Comment

    Working...
    X