A way to define rule for field to be submited

A way to define rule for field to be submited

toni.petrovictoni.petrovic Posts: 8Questions: 4Answers: 0

Dear all,

is there a way to define rule for the filed in the editor to be submitted or committed if the rule is not acceptable?

I know, you can define in the field the parameter submit (see example below), but can we do this programmatically - maybe in preSubmit event?

fields: [{
                    label: "Age:",
                    name: "age",
                    submit: false
                }]

I need this in the case, when I want user to submit a number and the empty string causes me a problem. I want to solve this on the javascript side!

Thank you and kind regards,
Toni

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Hi Toni,

    For client-side validation see this example.

    However, always do validation at the server-side. We focus on server-side validation rather than client-side, since you must do it at the server, so why bother duplicating the logic.

    Allan

  • toni.petrovictoni.petrovic Posts: 8Questions: 4Answers: 0

    Dear @allan ,

    I have validation on the other side, but for some fields I would like programmatically define if they should be send to the server side or not.
    Is there an option for that? (to somehow toggle submit option of the field, something like: this.field( 'first_name' ).submit(false))

    In your example it just shows hot to do the validation on the client side.

    Kind regards,
    Toni

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    Hi Toni,

    I see - sorry, I misunderstood. No, at the moment the submit option for a field cannot be toggled using the API. That's a good idea though - I will add that for 2.2 which I'm working on (it is likely a few weeks away though).

    Allan

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    To follow up on this, it never made it in to 2.2 (or 2.3), but it has now been committed for 2.4 :)

    Allan

Sign In or Register to comment.