add a mark to label to mark require input field

add a mark to label to mark require input field

hminhduchminhduc Posts: 22Questions: 13Answers: 1

How can mark a field on Editor to require input field. a red color or * mark.

Answers

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406
    edited September 2022

    If you use a validator and the field is a required field your field is marked in red automatically if you are not entering anything.

    The validators in PHP:

  • hminhduchminhduc Posts: 22Questions: 13Answers: 1

    I'm not using PHP, i using initSubmit and add field.error to show error message.
    so only message is red color not on field entry red as image.

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    You can also use field().message(), it may be less aggressive than field().error().

    Colin

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406

    so only message is red color not on field entry red as image.

    I might not fully understand this but using field().error() has the exact same effect than using a server side validator.

    I use the validator with "dependent" in this code example:

    editor
        .dependent('fixed.end_date', function (val, data, callback) {
            var tF = this.field('fixed.end_date');
            tF.error("");
            if ( val > "" ) {                    
                var inFiftyYears = moment().add(50, 'years').format('YYYYMMDD');
                var endDate = moment(val, 'L').format('YYYYMMDD');
                if ( endDate > inFiftyYears ) {
                    tF.error( lang === 'de' ? 'Sind Sie sicher, dass \n\
                      dieses Datum über 50 Jahre in der Zukunft liegen soll? \n\
                      Falls ja, ignorieren Sie bitte diese Warnung.' : 'Are you \n\
                      sure that this date should be in over 50 years from now? \n\
                      If so, please ignore this warning.' ); 
                }
            }
            callback({});
        })
    

    And this is what it looks like:

Sign In or Register to comment.