I have a text box with id "foo" that sometimes exists and sometimes not. If it exists, I would like to fill in a specific value.
How do you do this using RJS (in Rails 2.2)?
I tried this and it does not work:
if page[:foo] page[:foo].value = "bar" end
I get
TypeError: Null Value if the text field does not exist.
.
I have met this many times when I have a conditional element that I need to act on if it exists. Using page.select avoids the Null Value error.
page.select('#dom_object_id').each do |element| element.value = "bar" end
*.js.rjs. , TypeError, , DOM .
, RJS. javascript- RJS, , .
page << "update_foo('#{my_value}');"
Javascript..
function update_foo(val) { if( $('foo') != undefined ) { $('foo').value = 'bar'; } }
.
Source: https://habr.com/ru/post/1704500/More articles:In iPhone UIImageView, which method to override, for example, the init variable? - iphoneprototype / javascript - firefox does not fire the / keydown key event if focus is in the text box - javascriptIs there any reasonable SSDP or DIDL Lib for java / groovy / python? - javaПолучение "загрузки" системы в Windows - windowsSQL date picker - daterepeating data design - database-designMocking Objects When Using MSTest - .netLinq to sql: properties of properties that may be null - c #use accented characters with the Quickbooks SDK - c #MSSQL - Divide a field into 3 fields - sqlAll Articles