You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Eric R Glass/MAXIMUS <er...@maximus.com> on 2004/08/12 17:28:09 UTC

[PATCH] ValidField Fix for addSelect Method

Hi,

I found that if theValidField component is used on a page that is used for 
both editing and viewing the field depending on the user's permissions 
that the addSelect method will add JavaScript in certain conditions that 
causes an error.

If the field is required and empty, but the user is entering the page with 
view only permission, so the field is disabled, then the JavaScript is 
generated for the field and you get a JavaScript error in the browser. The 
field can be empty on our page with parent and child table information if 
the child information has not been created yet and in edit mode some of 
the child fields are required.

I found that the easiest way to fix this was to patch the addSelect method 
with the following code:

if (!isDisabled()) { // Added
 
            IForm form = Form.get(cycle);

            String formName = form.getName();
            String textFieldName = getName();

            String fullName = "document." + formName + "." + 
textFieldName;

            body.addInitializationScript(fullName + ".focus();");
            body.addInitializationScript(fullName + ".select();");

            // Put a marker in, indicating that the selected field is 
known.

            cycle.setAttribute(SELECTED_ATTRIBUTE_NAME, Boolean.TRUE);

 } // Added

I do not know if this could be made a patch to the Tapestry source in CVS 
or not; or something like it.

Eric Glass
MAXIMUS
ericglass@maximus.com