EasyUI Forum
May 01, 2024, 10:37:50 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Validate combobox on form submit?  (Read 6616 times)
joe
Newbie
*
Posts: 33


View Profile Email
« on: July 05, 2017, 11:39:13 AM »

How do i validate a combobox only on form submit?  Here is the code i use to submit the form.

Code:
$('#ff').form('submit',{
                onSubmit:function(){
                    return $(this).form('enableValidation').form('validate');
                }
            });

I initialized a combobox like this and it is validating as soon as the form is loaded.  I only want it to validate it on form submit:

Code:
$('#CityGroup').combobox({
            panelHeight: 'auto',
            selectOnNavigation: false,
            valueField: 'id',
            textField: 'text',
            editable: true,
            url: '/control/ajaxApp.aspx?a=getComboList&t=City_Group',
            required: true,
            validType: 'notFirst[\'-Select Security Group-\']'
        });
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: July 05, 2017, 05:02:41 PM »

Please look at this example https://www.jeasyui.com/demo/main/index.php?plugin=Form&theme=default&dir=ltr&pitem=Validate%20on%20Submit&sort=
Logged
joe
Newbie
*
Posts: 33


View Profile Email
« Reply #2 on: July 05, 2017, 09:21:02 PM »

Thanks for your replay.  The combobox on the example doesn't have a default selection, ie "- Select City -".  See my example, if I set the "required:true" attribute, the "- Select City -" default selection is a valid selection.  If I set the "validType: 'notFirst[\'- Select City -\']'", the combobox will show as an invalid selection as soon as the form load.

I only want the combobox to validate during on submit.
Logged
patana
Jr. Member
**
Posts: 50


View Profile
« Reply #3 on: July 10, 2017, 10:09:31 PM »

Let try:
First extend check validation to check when user key in.
Code:
$.extend($.fn.validatebox.defaults.rules, {
            check: {
            validator: function(value,param){
                    var obj = $(param[0]).combobox('getData');
                    var arr = [],n,result;
                    arr = $.map(obj,function(n,i){ n = n.textfield || n.text ; return n; });
            result = jQuery.inArray(value, arr);
            if(result == -1) return false;
            else return true;
            },
            message: 'Please fill it correctly!'
            }
    });

Add
Code:
validType="check['#company_name']"
to your combobox.
Define id=0 to your default text "- Select City -"
In my case i load data from server so i will do like:
Code:
$item = array('id'=>'0','text'=>'- Select City -');
$result = array();   
array_push($result, $item);

For form submit:
Code:
$('#fm').form('submit', {
            url: savedata_url,
            onSubmit: function(param) {               
                if ($('input[name=city_name]').val() === '0') {
                    msg = 'Please select City!';
                    $.messager.alert('Confirm', msg, 'info');
                    return false;
                } else
                    return $(this).form('validate');
            },
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!