-1

嗨,如何从下面的 html 中为这两个列表 event[] 和 qty[] 设置命令对象约束可为空、空白和自定义?

<div class="row-1">
    <select name="event[]" class="form-control ">
        <option selected="">abc</option>
        <option selected="">def</option>
    </select>
    <input name="qty[]" >
</div>
<div class="row-2">
    <select name="event[]" class="form-control ">
        <option selected="">ghi</option>
        <option selected="">jkl</option>
    </select>
    <input name="qty[]" >
</div>


class someCommand implements Validateable {

    List eventComponent
    List qty

    static constraints = {
    }
}
4

1 回答 1

0

嗨,我如何为这两个列表设置命令对象约束可为空、空白和自定义

你可以这样做:

class someCommand implements Validateable {

    List eventComponent
    List qty

    static constraints = {
        eventComponent nullable: false, validator: { theList ->
            // return true if theList is valid
            // return false or a message code if theList is invalid
        }
        qty nullable: false
    }
}

你不会blank使用List. blank用于验证String属性。如果要确保列表中包含元素,可以使用minSize: 1.

我希望这会有所帮助。

于 2019-12-10T18:02:49.333 回答