javascript - Rails 4 - Coffee script form helper & cross browser compatibility -
im using rails 4 make web app.
i have form in projects view folder, has nested questions. if answer top level question true, further sub questions displayed. if answer false, sub questions related top level question remain hidden.
i have form helper in javascripts folder has hide/show functions form. works fine when use chrome browser. doesn't work @ in safari. in safari, form elements, including supposed hidden @ start, displayed.
how adjust form helper works on browsers?
in js form helper file have:
# source input attrs: {class: 'toggle_div', target: <target_id_or_class>} # toggle_radio attr : {class: 'toggle_div', target: <target_id_or_class>, toggle_reverse: <anything> } #$ -> # $(document).on 'change', 'input.toggle_div', ()-> # $($(this).attr('target')).toggle this.checked # # $(document).on 'change', 'input.toggle_radio', ()-> # reverse = $(this).attr('toggle_reverse') # if reverse # toggle_value = ($(this).val() == 'false') # else # toggle_value = ($(this).val() == 'true') # target = $(this).attr('target') # $(target).toggle toggle_value #$ -> $ -> settheattributes = (instring)-> if $('#' + instring + '_sweep_attributes_if_datum').is(':checked') $('#datarequest').show() else $('#datarequest').hide() $(document).on 'change', '#' + instring + '_sweep_attributes_if_datum', ()-> if $('#' + instring + '_sweep_attributes_if_datum').is(':checked') $('#datarequest').show() else $('#datarequest').hide() formlist = document.getelementsbytagname "form" if(formlist[0].action.includes "/projects") settheattributes 'project' if(formlist[0].action.includes "/programs") settheattributes 'program' if(formlist[0].action.includes "/proposals") settheattributes 'proposal'
in application.js file have:
// manifest file that'll compiled application.js, include files // listed below. // // javascript/coffee file within directory, lib/assets/javascripts, vendor/assets/javascripts, // or vendor/assets/javascripts of plugins, if any, can referenced here using relative path. // // it's not advisable add code directly here, if do, it'll appear @ bottom of // compiled file. // // read sprockets readme (https://github.com/sstephenson/sprockets#sprockets-directives) details // supported directives. // //= require jquery //= require jquery_ujs //= require bootstrap //= require bootstrap-switch //= require_tree .
Comments
Post a Comment