View Full Version : [FIXED] markInvalid is not honored

28 Aug 2008, 6:20 AM
I assume when setting markInvalid on a TextField that the isValid flag returns false, but that's not the case with EXT GWT 1.1 Alpha2. It returns true.

package com.mygwtest.client;

import com.extjs.gxt.ui.client.Events;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.NumberField;

public class TestApp implements EntryPoint {

public void onModuleLoad() {
FormPanel panel = new FormPanel();
panel.setSize(400, 400);

final NumberField nf = new NumberField();

final TextField<String> test = new TextField<String>();

Button button = new Button("Click");
button.addListener(Events.OnClick, new Listener<ButtonEvent>() {
public void handleEvent(ButtonEvent be) {
nf.markInvalid("Testing invalidating functions");
test.markInvalid("Testing more...");




28 Aug 2008, 10:39 PM
Still does not work with GXT 1.1 Alpha3 and IE7 & FF3.0.1.

My oppinion is that if you mark a field invalid with markInvalid then the isValid should return false, not true as the case is now.

29 Aug 2008, 7:44 AM
well. i dont think it is a bug here

you mgiht be coding the validator wrong

isvalid checks stuff in validator

here is a simple of what a validator should be like

eclipseaccountnumber.setValidator(new Validator() {

public String validate(Field eclipseaccountnumber, String value) {
if (value.equals("")) {
return null;
try {
return null;
} catch (Exception e) {
return "Bad Eclipse Number";

when returning null it is valid if a string than it is invalid

29 Aug 2008, 7:47 AM
yep ur code is wrong. just looekd at it. hope my post above will let you know how to fix it

1 Sep 2008, 2:07 AM
But I don't want to use a validator in this case. I want to mark the field invalid with the method markInvalid. Why does not the markInvalid method set the isValid to false?


2 Sep 2008, 12:49 PM
well is valid runs the validators i think. markInvalid should really just be a private call but I guess it is useful if you have a validator for a field that might also affect another field.

So when that field gets checks after a change the markInvalid could change another field that was affected.

Example is like 2 fields for a date range.

If first field is greater than second fail the first will be invalid but second field wont yet unless u mark it as invalid.

Not sure if I am explaining clearly but I think thats the reason for markInvalid

3 Sep 2008, 12:29 AM
Nope, isValid should not run the validator methods, this is done with the validator() method. isValid should only return the current state in my opinion and the state should be able to be changed with either clearInvalid or markInvalid methods.

3 Sep 2008, 10:38 PM
Is this the official oppinion of the EXT-GWT team, that if I invoke the method markInvalid() on a component, this component shall still return true on isValid()? I think this is very strange.

In my case, I need to do a RPC-call to the server to validate the field. I don't see a way of doing this from a Validator-class. The validator class needs to do an instant return of either null or an error message. Doing a RPC call "returns" void and then you have to wait for the asynch answer. Making the validator wait for the response will not be a good solution I think.

I want to handle the valid-state of my component from my Controller-class not using any Validator implementation. If the methods: markInvalid() clearInvalid() and isValid() affected each other as their name suggests, I would have no problem implementing the logic I want.

Or do anyone have a better solution for me?

4 Sep 2008, 1:30 PM
u can just extend the class

make a boolean
if you want it to be that way

9 Sep 2008, 4:46 PM
This issue required a little refactoring to implement. This problem is that markInvalid is the same method that is called from validateValue so it is not possible to tell who is making the call. I have added a new method forceInvalid(String msg) which should be called when you want to override the validation code in a field. validateValue will return false, causing isValid to return false as well. The error will only be cleared by manually calling clearInvalid. markInvalid is now deprecated and its visibility will change to protected sometime in the future.

11 Dec 2008, 6:58 AM
Hi, I just started using GXT and I love it.

I just found a strange behaviour in my oppinion regarding the forceInvalid on Fields. I found many threads here discussing the forceInvalid in regards to RPC but I can't really find out what the result of the discussion is.

I use a textfield and create a validator for that field that makes a RPC to the serverside to validate the value. On Return I use the Field reference to set an error message on the field if it is wrong. However by doing that (if I use forceInvalid) I stop the field from being validated further. If I use markInvalid instead everything works like a charm but that method is marked deprecated.

public String validate(final TextField<String> field, String value) {
AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {
public void onSuccess(Boolean result) {
if (result)
//field.forceInvalid(); // Stops the validation from continuing
accountService.accountNameExists(value, callback);
return null;

Why not just leave the markInvalid method in there for those of us that like it? Am I missing something here?

Regards Fredrik

11 Dec 2008, 5:04 PM
Yes, you raise a good point, when validating with RPC you will want validation to be invoked after setting the error. I have removed the deprecated tag and updated the javadocs:

* Marks this field as invalid. Validation will still run if called again, and
* the error message will be changed or cleared based on validation. To set a
* error message that will not be cleared until manuall cleared see
* {@link #forceInvalid(String)}
* @param msg the validation message