1. #1
    Ext User fother's Avatar
    Join Date
    Sep 2007
    Location
    Brazil
    Posts
    744
    Vote Rating
    -1
    fother is an unknown quantity at this point

      0  

    Default form validation

    form validation


    Code:
    		final FormPanel form = new FormPanel();
    
    		final TextField<String> field = new TextField<String>();
    		field.setAllowBlank(false);
    		field.setRegex("[a-zA-Z]{3}");
    		field.getMessages().setRegexText("regex");
    		field.setValidator(new Validator<String, TextField<String>>() {
    
    			public String validate(TextField<String> field, String value) {
    
    				if (value.equals("aaa")) {
    					field.forceInvalid("aaa");
    				} else {
    					field.clearInvalid();
    				}
    
    				return null;
    			}
    
    		});
    
    		Button valid = new Button("mark valid");
    		valid.addSelectionListener(new SelectionListener<ComponentEvent>() {
    
    			@Override
    			public void componentSelected(ComponentEvent ce) {
    				field.clearInvalid();
    			}
    		});
    
    		Button invalid = new Button("mark invalid");
    		invalid.addSelectionListener(new SelectionListener<ComponentEvent>() {
    
    			@Override
    			public void componentSelected(ComponentEvent ce) {
    				field.forceInvalid("invalid");
    			}
    		});
    
    		Button test = new Button("test");
    		test.addSelectionListener(new SelectionListener<ComponentEvent>() {
    
    			@Override
    			public void componentSelected(ComponentEvent ce) {
    
    				if (form.isValid()) {
    					System.out.println("valid");
    				} else {
    					System.out.println("invalid");
    				}
    
    			}
    		});
    
    		form.add(field);
    		form.add(valid);
    		form.add(invalid);
    		form.add(test);
    
    		RootPanel.get().add(form);
    typed "aaa" in the field, and click on the button "test" - return valid, if you click again return invalid.

    in this method I need use "forceInvalid" and "clearInvalid", because I use a RPC that return if what the user typed isn't registered in data base.
    Code:
    			public String validate(TextField<String> field, String value) {
    
    				if (value.equals("aaa")) {
    					field.forceInvalid("aaa");
    				} else {
    					field.clearInvalid();
    				}
    
    				return null;
    			}
    any ideai?

  2. #2
    Ext User fother's Avatar
    Join Date
    Sep 2007
    Location
    Brazil
    Posts
    744
    Vote Rating
    -1
    fother is an unknown quantity at this point

      0  

    Default


    other question..

    typed "aaa" click on the button "test", return valid, click again, return invalid... now click on the button mark valid, then click on the button "test", return valid, click again return invalid...


  3. #3
    Ext User fother's Avatar
    Join Date
    Sep 2007
    Location
    Brazil
    Posts
    744
    Vote Rating
    -1
    fother is an unknown quantity at this point

      0  

    Default


    to solve this problem I need do this..

    Code:
    		Button test = new Button("test");
    		test.addSelectionListener(new SelectionListener<ComponentEvent>() {
    
    			@Override
    			public void componentSelected(ComponentEvent ce) {
    
    				field.isValid();
    
    				if (form.isValid()) {
    					System.out.println("valid");
    				} else {
    					System.out.println("invalid");
    				}
    
    			}
    		});
    bug?

  4. #4
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,966
    Vote Rating
    130
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    Yes, one within your code:


    Code:
    public String validate(TextField<String> field, String value) {
    
    				if (value.equals("aaa")) {
    					field.forceInvalid("aaa");
    				} else {
    					field.clearInvalid();
    				}
    
    				return null;
    			}
    http://www.extjs.com/deploy/gxtdocs/...a.lang.String)

    Still not reading the docs or?

  5. #5
    Ext User fother's Avatar
    Join Date
    Sep 2007
    Location
    Brazil
    Posts
    744
    Vote Rating
    -1
    fother is an unknown quantity at this point

      0  

    Default


    I was trying to simulate a problem .. I think no more successful .. rsss .. Next .. when we used to validate rpc .. takes a while to return a value and mark as invalid .. For example: to determine whether or not a record was saved in the database ..

    to solve this.. I needed validate on server, and return error

Thread Participants: 1

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar