Question about dynamic form values

37 views
Skip to first unread message

Alejandro Martinez

unread,
Aug 5, 2014, 6:17:52 AM8/5/14
to agile-too...@googlegroups.com
Hi,

I have a page that has a form with some fields and a label (HtmlElement - h3) with a number (ej. 100).

I'm trying to figure out how to do that when I input some numbers on the form fields, the number of the label gets automatically decremented.

For instance if the label is 100, then when I input 10 in the first field, then, the label says 90 (100 - 10), if I delete then 10, then the label says 100 .....

I'm trying to use js bindings or maybe in the $field->js('change') method but I'cant get the value of the field.

Thanks a lot.

Romans Malinovskis

unread,
Aug 5, 2014, 6:25:21 AM8/5/14
to agile-too...@googlegroups.com
php code:

$this->js()->_load('my_univ');
$h1 = $this->add('h1');
$field = $form->addField('item');
$field->js('change')->univ()->myremainder(100, $h1);


the my_univ.js:

myremainder: function(total, dest) {
  $(dest).text( total - this.jquery.val() );  
}

Hopefully this would work.

Alejandro Martinez

unread,
Aug 6, 2014, 1:41:42 PM8/6/14
to agile-too...@googlegroups.com
Romans, thank you very much for your reply.

I see that you pass a 'static' value (100) to the method 'myremainder'.

I have tried to modify your code to add two or more fields so when field1 change, then the value of the label is (for instance 100-10 = 90), and when the value of field 2 change (add 10), then the value of the label is 90 - 10 = 80....

Is it possible ?

and one more, how can I do to get a form value before the onsubmit() event.

If I do a

if ( $f->isSubmited() )
{
   $f->js()->univ()->alert($f->get('field') )
}

Everything works, but if I do a

$field->js('change')->univ()->alert($field->get('field') ) the output is null.

Thanks a lot.
Alejandro



--
You received this message because you are subscribed to the Google Groups "Agile Toolkit Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to agile-toolkit-d...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Romans Malinovskis

unread,
Aug 11, 2014, 4:43:27 PM8/11/14
to agile-too...@googlegroups.com
I can write a further documentation or tutorial on this, but I'm not sure which examples you would want me to cover. 

subtracting fields is something quite specific, it does require you to write a bit of custom javascript code.

Have you read all the docs in the JavaScript section of the book such as: http://book.agiletoolkit.org/js/univ.html

romans
To unsubscribe from this group and stop receiving emails from it, send an email to agile-toolkit-devel+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages