Welcome Guest, Not a member yet? Register   Sign In
Form validation for field create with jquery
#1

(This post was last modified: 12-04-2017, 02:59 PM by pippuccio76.)

Hi at all sorry for english, i am doing an invoice .
i have one row with input text  article name= 'article[1]' and input text quantity name= 'quantity[1]' .
With jquery i create a new row clicking a button for every click i add a row

the name of input are increase (f.e. article[2] and quantity[2] , article[3] and quantity[3])

How can i validate this value ,i want set required for this field ...
Reply
#2

You could try something like this:
(Not tested, probably full of bugs)
PHP Code:
$fields count($this->input->post());
for (
$i=1$i <= $fields; ++$i
{
    if ( ( ! empty(
$this->input->post('article'.$i)) AND ( ! empty($this->input->post('quantity'.$i)) )
    {
        
$this->form_validation->set_rule('article'.$i'Article '.$i'required');
        
$this->form_validation->set_rule('quantity'.$i'Quantity '.$i'required|integer');
    }


I think that should work. May not be the cleanest or neatest way to achieve this but it is one possible way.

Paul.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB