nested_form icon indicating copy to clipboard operation
nested_form copied to clipboard

Uses length validation to hide add link when you reach maximum # of nested objects

Open SebastianEdwards opened this issue 14 years ago • 5 comments

Hides the add link when reaches maximum number of nested objects as defined in length validation. Ie.

class Project < ActiveRecord::Base
  has_many :tasks
  validates :tasks, :length => { :in => 1..3 }
end

Adds the attribute 'data-maximum' to the link and checks this against the number of visible nested entries on both add and remove and also on page load.

Have changed jQuery template only as am not familiar with Prototype. Probably should be altered to bind to the 'nested:fieldAdded' and 'nested:fieldRemoved' triggers.

Hope this is useful.

SebastianEdwards avatar May 26 '11 23:05 SebastianEdwards

Cool idea. Anyone want to add this to the prototype javascript file?

ryanb avatar May 27 '11 16:05 ryanb

Works perfectly!

What do I have to change if I want to hide the remove links for a data minimum, though?

mexxer avatar Aug 11 '11 18:08 mexxer

Has this been added to the most recent commit?

godalphul avatar Sep 24 '11 10:09 godalphul

Sad to see this wither on the vine. Would be very helpful!

avk avatar Oct 29 '12 19:10 avk

I migrated a lot of this work forward. Will be ready by EOW. Backwards compatible.

michaelglass avatar Feb 19 '13 18:02 michaelglass