Support » Plugins » Hacks » generate input fields in widget config

  • Resolved jerodev



    I was wondering if it is possible to generate input fields in the widget config field using javascript. And if so, how can I get the data from them?

    I want the admin to be able to select a value form a combobox and put a button next to it to create another combobox to select another value. But how do I name this new combobox and how do I get the data in the widget class?

    Thank you,

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz


    I haven’t done this, but I think it’s possible. You may be better off defining the second box from the beginning, you can hide it with css if you want. It’s only value could be “Pick from 1st combo”.

    Based on the first combo pick, javascript can populate the correct values for the second, using ajax if need be. When the form is submitted, the values are passed to the widget’s update function as any other field. As long as update() knows what field name to expect, whether preassigned or assigned by javascript, it all should work out.

    The problem is that I would like to be able to create an unknown number of comboboxes.
    I don’t know the number in advance.

    Moderator bcworkz


    There must be some upper limit? Assume worst case, anything with default value was not used.

    Or if you want to generate the entire combo box on the fly, give them sequential names like info01, info02, info03 etc. Then use isset() in the widget’s update() to determine whether a particular name is used.

    Since the values are stored in an object, you can build name strings on the fly, then use them to access each value:

    for ($i = 1; $i <= 10; $i++){
    $name = 'info0' . strval($i);
    //do stuff

    Thanks for the help.
    I have solved the problem by generating the fields with javascript and storing the values of all combo boxes in a hidden input with a correct wordpress name. I set this value with every onchange of a combo box.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘generate input fields in widget config’ is closed to new replies.