On Mon, Nov 20, 2017 at 10:32 PM, Craig Russell <apache....@gmail.com> wrote: > >> On Nov 20, 2017, at 7:04 PM, Sam Ruby <ru...@intertwingly.net> wrote: >> >> On Mon, Nov 20, 2017 at 8:22 PM, Craig Russell <apache....@gmail.com> wrote: >>> I have a bug that I cannot figure out. >>> >>> Load the demo whimsy/project/icla and the form shows up just fine. Since >>> the fields are not filled, the (Preview Invitation) button is not active. >>> The form fields are outlined in red, indicating that there are errors >>> (empty is not an option here). >>> >>> Fill the three form fields and the (Preview Invitation) button is still not >>> active. It should be active. >>> >>> Change the project and the (Preview Invitation) button is active. >>> >>> There is also a message, perhaps related, on the javascript console: >>> >>> [Error] TypeError: null is not an object (evaluating >>> 'document.getElementById(id).checkValidity') >>> (anonymous function) (app.js:668) >>> every >>> checkValidity (app.js:667) >>> setPMC (app.js:591) >>> >>> The way this should work is that if the vote/notice field is filled, it is >>> validated against the current pmc field value. This part seems to work ok, >>> but the enabling of the preview the first time the pmc field is filled is >>> not working. >>> >>> Any ideas? >> >> Here's the code: >> >> def checkValidity() >> @disabled = !%w(iclaname iclaemail pmc votelink noticelink).all? do |id| >> document.getElementById(id).checkValidity() >> end >> end >> >> Once EVERY one of those fields is valid, @disabled will be set to >> false. At which point, preview invitation will no longer be disabled: >> >> _button.btn.btn_primary 'Preview Invitation', disabled: @disabled, >> onClick: self.previewInvitation >> >> Since you are getting an error message, one of those fields is not >> present (in other words, document.getElementById(id) returns null). > > Yes, and it must be one of the votelink/noticelink fields. > > I create these fields only after the pmc field is filled. > > Do I need to create them first and only enable them once the pmc field is > filled? How would I do that?
A better question: when do you want the Preview Invitation button to be enabled? I would suggest changing the checkValidity method. One possible solution: element = document.getElementById(id) element and element.checkValidity() Another possible solution: element = document.getElementById(id) (not element) or element.checkValidity() These two approaches will have different behavior. The first will require all fields to (eventually) be revealed and be valid. The second will only validate the fields that are shown. - Sam Ruby >>> Craig L Russell >>> Secretary, Apache Software Foundation >>> c...@apache.org http://db.apache.org/jdo >> >> - Sam Ruby > > Craig L Russell > Secretary, Apache Software Foundation > c...@apache.org http://db.apache.org/jdo >