Forum: Ruby on Rails text_field_tag

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Daniel S. (Guest)
on 2007-01-30 20:02
can you use :confirm => 'great consequences', :post => true within
text_field_tag options?

I'm trying to confirm with users that changing that particular field
will have great consequences.
Stephen B. (Guest)
on 2007-01-30 20:15
(Received via mailing list)
Not really no.  But you can add standard javascript event like this:

<%= text_field_tag 'my_text_field', :onchange => "alert('Changing this
field will have great consequences')" %>

Steve
Daniel S. (Guest)
on 2007-01-30 20:27
ah yes, thanks...



Stephen B. wrote:
> Not really no.  But you can add standard javascript event like this:
>
> <%= text_field_tag 'my_text_field', :onchange => "alert('Changing this
> field will have great consequences')" %>
>
> Steve
Daniel S. (Guest)
on 2007-01-30 21:26
Im not too hot with the javascript...
I wanted the message to show only after the form is submitted and not
just changing the field and clicking off.



Daniel Salo wrote:
> ah yes, thanks...
>
>
>
> Stephen B. wrote:
>> Not really no.  But you can add standard javascript event like this:
>>
>> <%= text_field_tag 'my_text_field', :onchange => "alert('Changing this
>> field will have great consequences')" %>
>>
>> Steve
Stephen B. (Guest)
on 2007-01-30 21:38
(Received via mailing list)
Ah ok - that's going to require a bit more work - more than one post's
worth :0).  You'll need to create a javascript function that is called
when you submit the form.  That is reasonably straight forward.
However, in order to work out if the field has changed, you'll need to
either use onchange to set a variable stating the change or have a
hidden field with old value so you can compare.  The function would
look something like this:

function checkForm() {
    // your statement would need to work out if the field had been
changed
    if(field_has_changed) {
       return confirm('Changing this field will have great
consequences');
    }
}

And in the form submit you'll have 'return checkForm()'

Hope that makes sense - you'll need to do a bit of googling to work
out the rest of the code but hopefully I've put you in the right
direction :0)

Steve
Daniel S. (Guest)
on 2007-01-30 21:52
Thanks for the reply... after doing the checkForm I realize the prompt
is too harsh (visually harsh), so im thinking about putting this into
ajax instead.  So now I've changed my hunt to a nice ajax script:)



Stephen B. wrote:
> Ah ok - that's going to require a bit more work - more than one post's
> worth :0).  You'll need to create a javascript function that is called
> when you submit the form.  That is reasonably straight forward.
> However, in order to work out if the field has changed, you'll need to
> either use onchange to set a variable stating the change or have a
> hidden field with old value so you can compare.  The function would
> look something like this:
>
> function checkForm() {
>     // your statement would need to work out if the field had been
> changed
>     if(field_has_changed) {
>        return confirm('Changing this field will have great
> consequences');
>     }
> }
>
> And in the form submit you'll have 'return checkForm()'
>
> Hope that makes sense - you'll need to do a bit of googling to work
> out the rest of the code but hopefully I've put you in the right
> direction :0)
>
> Steve
Stephen B. (Guest)
on 2007-01-30 22:00
(Received via mailing list)
I'm not sure it's AJAX specifically that you're after as you don't
need to post back to the server for this.  I would however recommend
that you look at Scriptaculous (http://wiki.script.aculo.us/
scriptaculous/show/CombinationEffectsDemo) if you want to display a
message in neat 'web 2.0' style.  Scriptaculous is included with
Rails, so it's all there ready to play with.

Steve
Daniel S. (Guest)
on 2007-01-30 22:05
That's exactly where I am!
thanks.

Stephen B. wrote:
> I'm not sure it's AJAX specifically that you're after as you don't
> need to post back to the server for this.  I would however recommend
> that you look at Scriptaculous (http://wiki.script.aculo.us/
> scriptaculous/show/CombinationEffectsDemo) if you want to display a
> message in neat 'web 2.0' style.  Scriptaculous is included with
> Rails, so it's all there ready to play with.
>
> Steve
This topic is locked and can not be replied to.