Making a dropdown field a mandatory field

Making a dropdown field a mandatory field

GaneshmurthyGaneshmurthy Posts: 1Questions: 1Answers: 0

Hi All,
I have a dropdown field in datatables and want to make it mandatory field. If the value is "select one' then I should prompt a message below the dropdown field. EditorField.error works only for textbox.
Can anyone shed some light to get this resolved?
Thanks in advance.
Ganesh

Answers

  • hnhegdehnhegde Posts: 68Questions: 17Answers: 0

    I am looking for a simple way to say an Editor field is mandatory. Akin to the "required" attribute in html5. Surprisingly, cant find any. Kindly advise,

    Thanks,
    Harsha

  • allanallan Posts: 61,664Questions: 1Answers: 10,095 Site admin

    Hi Harsha,

    There are a few options for this. A CSS class for the fields in question that would style them differently is on option. An asterisk in the field label is another option.

    Allan

  • hnhegdehnhegde Posts: 68Questions: 17Answers: 0

    Allan,
    We ended up writing a javascript validation function and passed an array of field names from each table requiring validation. Coupled with visual cues - like red asterisk to prompt the user.

    function check_mandatory_fields(editor, fields ){
        var ret_value = true;
        for( var i = 0; i < fields.length; i++){
            fieldname = fields[i];
            field_obj = editor.field(fieldname);
            if ((field_obj.val() == null) || (field_obj.val() == '')){
    
                field_obj.error('Mandatory Field');
                ret_value = false;
            }
            else{
                field_obj.error(null);
            }
        }
        return ret_value;
    }
    

    And in the table "preSubmit" -

    table_A.on('preSubmit', function(e, o, a) {
                   check_mandatory_fields(table_A, ['field1', 'field2']);
                    if (this.inError()) {
                        return false;
                    }
                });
    
This discussion has been closed.