You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by George Christman <gc...@cardaddy.com> on 2012/06/05 20:08:39 UTC

Clear clientside validation from tapestrys memory.

Hello, I've built a dynamic validation component which enables fields to be
dynamically required depending on either the forms workflow state or the
particular action button used. I only want to validate required fields when
the form is "Submit" to the next state, but when the form is "Saved" I only
want to do a sanity check validation, ie field lengths etc. When the form is
first rendered, I do not setup clientside validation for required fields do
to the fact the "Submit" action button hasn't been selected. However all
other clientside validation has been setup. This part works perfectly fine
as long as I don't "Submit" the form. As soon as I submit the form, the
required fields are now recorded as being a part of the clientside
validation when the page renders the validation errors. 

My question is there a way to clear Tapestrys memory of clientside
validation preventing required fields from becoming a part of my clientside
validation?


My code looks like this. 

.tml 
<t:TextField t:id="allocatedTotal" 
t:validate="prop:purchaseRequestValidation.getFieldValidatorComponent(allocatedTotal,
'regexp,maxScale=2,maxPrecision=10')"/>

private Integer action;

void onAction(Integer action) {
this.action= action;
}

.java
    public FieldValidator FieldValidator(Field field, String validatorType)
{
        String[] validators =
TapestryInternalUtils.splitAtCommas(validatorType);
        
        List<FieldValidator> fieldValidators =
CollectionFactory.<FieldValidator>newList();
        
        for (String spec : validators) {
            String constraintValue = parseConstraint(spec);
            validatorType = parseValidator(spec);   

            if("required".equalsIgnoreCase(validatorType) || spec.isEmpty())
{
                break;
            }
           
            ValidatorSpecification originalSpec = new
ValidatorSpecification(validatorType, constraintValue);
            
            fieldValidators.add(source.createValidator(field,
originalSpec.getValidatorType(), originalSpec.getConstraintValue()));
        }
        
        fieldValidators.add(source.createValidator(field,
hasValidation(parseClientId(field.getControlName()), this.action), null));
        
        return new CompositeFieldValidator(fieldValidators);  
    }

    public String hasValidation(String clientId, Integer action) {
     
        //List of fields from the database requiring validation
        for(FormValidation formValidation : this.formValidations) {
            //Field requiring validation
            String field = formValidation.getFormField().getDbTableField();

            //Action Button Requiring validation. 
            Integer _action = formValidation.getApplicationAction().getId();

            //compares current field with database fields along with click
action with database action
            if(field.equalsIgnoreCase(clientId) && _action == action) {
                return "required";                
            }            
        }
        return "none";
    }

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Clear-clientside-validation-from-tapestrys-memory-tp5713644.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Clear clientside validation from tapestrys memory.

Posted by George Christman <gc...@cardaddy.com>.
Resolved, Manu suggested creating a new required validator leaving out the
render method. This worked perfectly. 

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Clear-clientside-validation-from-tapestrys-memory-tp5713644p5713718.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Clear clientside validation from tapestrys memory.

Posted by George Christman <gc...@cardaddy.com>.
Does anybody know how to control what validation scripts are being added to
the interface?

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Clear-clientside-validation-from-tapestrys-memory-tp5713644p5713700.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org