cal-itp / benefits

Transit benefits enrollment, minus the paperwork.
https://docs.calitp.org/benefits
GNU Affero General Public License v3.0
27 stars 9 forks source link

Custom validation messages not working in in-person eligibility form #2337

Closed angela-tran closed 1 month ago

angela-tran commented 2 months ago

The mockups show that the in-person eligibility form should show custom validation messages - "Please choose an eligibility type." for the radio buttons and "Please confirm you have used an agency policy to verify eligibility." for the checkbox.

The current implementation in #2317 is using our generic form.html template to render the forms, which has logic to handle custom validation messages, so it should just work, but it is not. Let's debug it.

angela-tran commented 1 month ago

I found out that the problem is in this line: https://github.com/cal-itp/benefits/blob/99500c88c62209b777a469a5a419e2c9453731ec/benefits/core/templates/core/includes/form.html#L73

Here we're passing in a selector of button[type=submit] and a context of #{{ form.id }} to find the submit button that should trigger validation logic. But in in_person/eligibility.html, the submit button is not inside the <form> element; instead it's outside the <form> element and has a form attribute, which is also a valid approach.

I think we could fix this by adding a query for a button[type=submit] with a form attribute of #{{ form.id }} if the existing query doesn't find anything.

thekaveman commented 1 month ago

I think we could fix this by adding a query for a button[type=submit] with a form attribute of #{{ form.id }}

Take a look at the .add() jQuery helper.