Posted By

smoothdzion on 12/18/09


Tagged

rails ruby jquery helper ror


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

smoothdzion


RoR Helper - Copy Input Value if Empty


 / Published in: Rails
 

I needed to copy the value of one field to a couple of others in case users decided to forget to fill them out. Using jQuery and added it to a helper because I was using in multiple places. Created variables to make it more readable.

  1. def name_copy(model)
  2. '<script type="text/javascript" charset="utf-8">
  3. var n = $("input#' + model + '_name");
  4. var t = $("input#' + model + '_title");
  5. var st = $("input#' + model + '_seo_title");
  6. var su = $("input#' + model + '_seo_url");
  7.  
  8. n.blur(function(){
  9. if(t.val()==0){
  10. t.val(n.val());
  11. };
  12.  
  13. if(st.val()==0){
  14. st.val(n.val());
  15. };
  16.  
  17. if(su.val()==0){
  18. su.val(n.val());
  19. };
  20. });
  21. </script>'
  22. end

Report this snippet  

You need to login to post a comment.