Is there a method in JQuery similar to "is_unique" in Codeigniter-4

33 Views Asked by At

I want to ask if is_unique in CodeIgniter 4 is available in jQuery Validate?

I'm trying to solve my coding problem which involves the is_unique validation from CodeIgniter 4.

Here is sample of my code in view.php

<script>
    $(document).ready(function() {
        if ($('.formsave').length > 0) {
            $('.formsave').validate({
                rules: {
                    catcode: {
                        required: true,
                        is_unique: true --> this is the problem, although i'm just triying something here (testing)
                    },
                    catname: {
                        required: true,
                    },
                    catstatus: {
                        required: true
                    },
                },
                messages: {
                    catcode: {
                        required: "Please enter category code such as F & B",
                        is_unique: "Sorry, category code already taken, please choose another code for this category!"
                    },
                    catname: {
                        required: "Please enter category name such as Food & Beverage",
                    },
                    catstatus: {
                        required: "Please select Enable or Disable for the category You created",
                    },
                },
            })
        }
    });
</script>

and here is my controller in View.php

public function validTest()
{
    $rules = [
             'catcode'   => 'required|is_unique[tbcat.cat_code]',
             'catname'   => 'required|is_unique[tbcat.cat_name]',
             etc.
    ];

    if(! $this->validate($rules) {
             // something here
    } else {
             //  another something here
    }
}

is there any method using is_unique within jQuery Validate?

0

There are 0 best solutions below