I’ve searched all over for an answer to this, but cannot find any clear examples for what I’d like to do. I have worked to provide this functionality in native JavaScript (getDocumentiD) in the past, but I’d like to know the easiest way to do this in the Yii framework.
What I’d like to do is using the CJuiAutoComplete class, autofill particular fields by adding, dividing, or multiplaying values given from PREVIOUSLY entered fields in a form. I would like this to update dynamically as the values are changed. If anyone could outline the appropriate steps or examples, or a link to a guide I would greatly appreciate it!
I would also like to achieve something similar for one particular field in my form. What I’d like to do is given the input from a previous field e.g (country name), look up my database for that model all corresponding rows that contain that same previously entered country from the form, take the average of an integer in a column for all those rows, and autofill ANOTHER field on the form.
If anyone could give any clear examples of this I would greatly appreciate it.
I don’t think CJuiAutoComplete will do what you’re hoping to do, as that class is a wrapper around http://jqueryui.com/demos/autocomplete/, which basically provides suggestions as you complete a form, not calculating values based upon other form inputs.
For your question, the general overview is that you’ll want to attach an AJAX call to your listbox in your view, something along the lines of:
The above code creates a listbox with attached AJAX. In your controller, you’d then have something like:
The auto-update then happens as the success function in the AJAX is called, and the part of the page with id ‘secondField’ will be updated to have the value you returned.