0

I'm trying to validate with parsley but by adding a data-parsley-min="1" to my input loop will add them to all of them.

For some reason it's not working now and I'm thinking it's because the multiple data-parsley-min="1" attributes.

Here's my code:

<form id="questionSubmitForm" data-parsley-validate="">
    <div class="form-group">                                    
        <label class="font-weight-bold" for="prechecks">Pre-checks</label>
        <div class="form-check" th:each="researchType : ${question.research}">
            <input class="form-check-input" type="checkbox" name="prechecks[]" th:value="${researchType.value}" data-parsley-mincheck="1">
                <label class="form-check-label" th:for="${researchType.value}" th:text="${researchType.key}"></label>                            
        </div>
    </div>
</form>

1 Answers1

0

You can use th:attrappend (and the iteration status -- notice the , i in the th:each attribute) for this:

<form id="questionSubmitForm" data-parsley-validate="">
    <div class="form-group">                                    
        <label class="font-weight-bold" for="prechecks">Pre-checks</label>

        <div class="form-check" th:each="researchType, i : ${question.research}">
            <input class="form-check-input" type="checkbox" name="prechecks[]" th:value="${researchType.value}" th:attrappend="data-parsley-mincheck=${i.index == 0 ? 1 : ''}" />
            <label class="form-check-label" th:for="${researchType.value}" th:text="${researchType.key}"></label>                            
        </div>
    </div>
</form>
Metroids
  • 18,999
  • 4
  • 41
  • 52