Text_field_tag


#1

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.


#2

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


#3

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


#4

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


#5

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


#6

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


#7

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


#8

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