Guest User

Untitled

a guest
Jan 24th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. JQuery ->
  2. $('a#add_image_form').click ->
  3. regex = /add_image_form_\d{1,3}/
  4. data = $(this).attr('data').toString()
  5.  
  6. imgId = data.match(regex)[0].match /\d{1,3}/
  7. newId = parseInt(imgId) + 1
  8.  
  9. newData = "add_image_form_".concat(newId)
  10.  
  11. $(this).attr('data', newData)
  12.  
  13. $(this).parent().before("
  14. <p>
  15. <label for='gallery_pictures_attributes_#{newId}_caption'>Caption</label>
  16. <input id='gallery_pictures_attributes_#{newId}_caption' name='gallery[pictures_attributes][#{newId}][caption]' size='30' type='text' />
  17. </p>
  18. <p>
  19. <input id='gallery_pictures_attributes_#{newId}_image' name='gallery[pictures_attributes][#{newId}][image]' type='file' />
  20. </p>
  21. ")
Add Comment
Please, Sign In to add comment