Okay, I came up with a JS/prototype solution to this - it may not be a
perfect one, but it works. Here's what I did:

1) I have removed the required validator from the form's only input field

2) I have removed the <t:submit /> button and replaced it with an ordinary
<input type="button" ... /> which calls a confirmBlank(this.form) JS
function in its onClick handler, passing it the form reference.

3) The JS function then checks for the input field's value, and explicitly
fires the form submit event if either the input field is filled-in, or if it
is blank and user confirms that it is OK:

function confirmBlank(form)
{
        var value= form['currentValue'];
        if($(value).getValue().length == 0)
                if(!confirm('Are you sure you want to submit a blank value?'))
                        return;
        
        form.fire(Tapestry.FORM_PROCESS_SUBMIT_EVENT);
}

So far this approach seems to be working fine, and I like its simplicity. It
doesn't even require hooking into Tapestry.ZONE_UPDATED_EVENT so it should
be Tapestry 5.0.x compatible (haven't tried that though).

Thanks again for all the help! :-)
Rado



immutability wrote:
> 
> Now - I have one more problem. For the form, I need something like
> "interactive validation". Basically, rather than using a "required"
> validator, I just need to display the javacript confirm dialog to the user
> if the field is empty, to ensure that they really want to save an empty
> value.
> 
> In traditional JavaScript, I would just do this:
>   return confirm('Are you sure to save a blank value?') 
> in the onSubmit handler of the form. 
> 
> But this won't work here. So I was thinking that perhaps I should just use
> the "required" validator, but handle the Tapestry.FORM_VALIDATE_EVENT and
> display the prompt here - and in case the user confirms, just set form's
> validation error to false (to allow it to be submitted even if the
> required validator failed). But this doesn't seem to do the trick. Is this
> a completely wrong way?
> 
> Thanks again,
> Rado
> 

-- 
View this message in context: 
http://old.nabble.com/T5%3A-Using-Event.observer-with-a-form-within-a-t%3Ablock-tp28697334p28742904.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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

Reply via email to