Is it possible to indicate which fields are mandatory

Is it possible to indicate which fields are mandatory

pzh20pzh20 Posts: 66Questions: 15Answers: 0
edited July 2015 in Editor

When the Editor modal pops up to add or edit a record, is it ossible to show which fields are mandatory?

Regards
Pete

This question has an accepted answers - jump to answer

Answers

  • AshbjornAshbjorn Posts: 55Questions: 2Answers: 16
    edited July 2015 Answer ✓

    Hi pzh20,

    It depens whether you want to achieve this client-side or server side.

    If you want to do it client-side I'd suggest implementing the preSubmit which is fired just before the submit takes place. By returning false in this method you can prevent the submit from happening:

        editor.on( 'preSubmit', function ( e, o, action ) {
            if ( action !== 'remove' ) {
                if ( o.data.first_name === '' ) {
                    this.error('first_name', 'A first name must be given');
                    return false;
                }
                else if ( o.data.first_name.length >= 20 ) {
                    this.error('first_name', 'The first name length must be less that 20 characters');
                    return false;
                }
            }
        } );
    

    If you want to implement this server-side I'd suggest you take a good close look at the examples provided in the reference documentation for using Validators in PHP and Validators in .NET.

    @Allan, how do you link to the editor code references? Hmm, just purchased Editor, but I still can't link to references there :(

    Hope this helps,

  • pzh20pzh20 Posts: 66Questions: 15Answers: 0

    Thanks Alan, just what I needed.

    Pete

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

    @Ashbjorn - There is some documentation about this in tech note 8 - just replace the dt- prefix with e- (for Editor).

    @pzh20 - There are a couple of other options for showing visually which fields are mandatory before the user submits invalid data:

    Allan

  • pzh20pzh20 Posts: 66Questions: 15Answers: 0

    Actually, rethinking this, it still doesn't highlight the fields that are mandatory before being submitted. Is there no way to do what you might do with any input form and show the required fields?

    Regards
    Pete

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

    I think we may have overlapped - see my comment above :-)

    Allan

This discussion has been closed.