I am trying to create a step form – which triggers/shows some fields when something else is chosen.
Here is an example – http://jsfiddle.net/XnPZF/ – of it working (it also works in development).
Just can’t figure out why this doesn’t work when I push to Heroku.
Here is a version on Heroku.
Login credentials: abc@test.com/test123
The fields that should trigger other fields right below it are Property_Type & Category.
Here is a snippet of some code:
/views/listings/new.html.erb
<%= simple_form_for @listing, :html => { :class => 'form-horizontal' } do |f| %>
<%= f.error_notification %>
<fieldset>
<%= f.association :property_type %>
<div style="display: none;" data-show-for-prop-type="Multi Family">
<h4>Multi-Family</h4>
<%= f.input :taxes %>
<%= f.input :house_families %>
<%= f.input :house_extensions %>
<%= f.input :house_stories %>
<%= f.input :house_units %>
</div>
<div style="display: none;" data-show-for-prop-type="Condo">
<h4>Condo</h4>
<%= f.input :taxes %>
<%= f.input :common_charges %>
</div>
The listings.js file:
$('#listing_property_type_id').on('change', function(){
var option = $(this).find(':selected');
$('[data-show-for-prop-type]').hide(); //And maybe reset?
$('[data-show-for-prop-type='+ option.text() +']').show();
});
Seeing several JS errors on realty-cloud.herokuapp.com/listings/new… “Uncaught TypeError: Cannot read property ‘oApi’ of undefined”. Almost positive that might be the issue.
The reason Dev did not have the problem is because in dev, it was separate assets, therefore the error was confined to that one js file with that error. However since the asset pipeline compiles into one, errors stop the rest of it’s execution.
Best bet, fix all console errors, or add “undefined” checks to prevent those such “Uncaugh TypeError” errors.