javascript - How to specify a css location except one area ? Rails -
here view :
<body > <table class="table canvas" cellspacing=0 > <tr class="twenty"> <th colspan=2>kp</th> <th colspan=2>ka</th> <th colspan=2>vp</th> <th colspan=2>cr</th> <th colspan=2>cs</th> </tr> <tr class="twenty" > <td rowspan=3 colspan=2 > <%= render @blocks[0] %> </td> <td colspan=2> <%= render @blocks[1] %> </td> <td rowspan=3 colspan=2> <%= render @blocks[2] %> </td> <td colspan=2> <%= render @blocks[3] %> </td> <td rowspan=3 colspan=2> <%= render @blocks[4] %> </td> </tr> <tr class="twenty" > <th colspan=2>kr</th> <th colspan=2>ch</th> </tr> <tr class="twenty" > <td colspan=2> <%= render @blocks[5] %> </td> <td colspan=2> <%= render @blocks[6] %> </td> </tr> <tr class="fifty"> <th colspan=5>c$</th> <th colspan=5>rs</th> </tr> <tr class="fifty" > <td colspan=5> <%= render @blocks[7] %> </td> <td colspan=5> <%= render @blocks[8] %> </td> </tr> </table> </body>
each render blocks[x] renders :
<%= form_for block, :html => { :id => "block_"+block.id_case.to_s} |f| %> <%= f.text_area :content, :size => "5x4" %> <%= f.hidden_field :id_case %> <%= f.hidden_field :canvas_id %> <%= f.submit "save" %> <% end %>
so each form hash id "block_1", "block_2" et cetera.
it creates forms :
<form accept-charset="utf-8" action="/blocks/11" class="edit_block" id="block_1" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="_method" type="hidden" value="put" /><input name="authenticity_token" type="hidden" value="xztxw50p1m0gxd9yysjfzdvy+/6hrtd+rupvx09qwt4=" /></div> <textarea cols="5" id="block_content" name="block[content]" rows="4"> development</textarea> <input id="block_id_case" name="block[id_case]" type="hidden" value="1" /> <input id="block_canvas_id" name="block[canvas_id]" type="hidden" value="1" /> <input name="commit" type="submit" value="save" /> </form>
my point when writing in textarea, clicks somewhere else textarea, clicks ont "save" button.
i've written little bit of javascript code test :
var test=false; $('form#block_1.edit_block textarea#block_content').click(function() { test=true; } ) $('body').on('click', 'td', function(){ if (test) { $('form#block_1.edit_block input').trigger('click'); test=false } });
but when open javascript console in chrome, each time try click elsewhere in textarea, receive message :
uncaught rangeerror: maximum call stack size exceeded
someone can tell me comes , how fix ? not convenient css location.
thank you.
change
var test=false; var alreadyincallback = false; $('form#block_1.edit_block textarea#block_content').click(function() { test=true; } ) $('body').on('click', 'td', function(){ if (test && !alreadyincallback) { alreadyincallback = true; $('form#block_1.edit_block input').trigger('click'); alreadyincallback = false; test=false } });
Comments
Post a Comment