Broetchen1234 / iui

Automatically exported from code.google.com/p/iui
MIT License
0 stars 0 forks source link

Posting of toggle states #212

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Toggle data is not added to the post body when for data is sent.
This can be solved by using a checkbox instead or by adding the following
to the encodeForm method (the encodeToggles function and call):

function encodeForm(form)
{
  function encode(inputs)
  {
    for (var i = 0; i < inputs.length; ++i)
    {
      if (inputs[i].name)
        args.push(inputs[i].name + "=" + escape(inputs[i].value));
    }
  }

  function encodeToggles(toggles) {
    var i,t,n,state;
    for (i=0; (t=toggles[i]); i++) {
      n = t.getAttribute('name');
      if (n) {
        state = String(!!(t.getAttribute('toggled')==='true'));
        args.push(n + "=" + state);
      }
    }
  }

  var args = [];
  encode(form.getElementsByTagName("input"));
  encode(form.getElementsByTagName("textarea"));
  encode(form.getElementsByTagName("select"));
  encodeToggles(form.getElementsByClassName("toggle"));
  return args;  
}

Original issue reported on code.google.com by rikkertk...@gmail.com on 3 Jan 2010 at 12:06

GoogleCodeExporter commented 9 years ago
Note this requires a "name" on the toogle div:

<div class="toggle" name="foo">

It will submit the string "true" or "false"

Original comment by rikkertk...@gmail.com on 3 Jan 2010 at 12:09

GoogleCodeExporter commented 9 years ago
Another option, which doesn't involve altering iui.js, is to put listeners on 
the
toggle and change the value of a hidden input when the toggle is switched.

I agree that this should be part of the basic functionality though; it seems 
weird to
have put work into building the toggle element but not making it part of a form.

Original comment by mike...@gmail.com on 16 Mar 2010 at 4:28

GoogleCodeExporter commented 9 years ago
I am a newbie to iui and js.  The above iui.js changes do not seam to work for 
me.  I have several toggles which I need to pass to a php script via post. 
Miken32's comments seem a good option but how do I link each toggle button to a 
specific hidden input?  for example if I had two toggles named food and drink, 
how can I set two hidden inputs named food and drink to reflect the state of 
the toggles?  

Original comment by tstreatf...@gmail.com on 26 Oct 2010 at 7:08

GoogleCodeExporter commented 9 years ago
hi

i am also a newbie and don´t understand how to get this to work?

i got a simple toggle site showing if lights is on or off

   <div id="light" title="Lights" class="panel">
        <h2>Status</h2>
        <fieldset>
            <div class="row">
                <label>Room1</label>
                <div class="toggle" name="room1" onclick=""><span class="thumb"></span><span class="toggleOn">ON</span><span class="toggleOff">OFF</span></div>
            </div>
            <div class="row">
                <label>Room2</label>
                <div class="toggle" name="room2" onclick="" toggled="true"><span class="thumb"></span><span class="toggleOn">ON</span><span class="toggleOff">OFF</span></div>
            </div>
        </fieldset>
        <form action="save.php" method="post" name="test">
        <input type="submit" value="Submit">
        </form>
    </div>

what musst i do to get the value of the toggles to the save.php script.
don´t understand how to use the script in post number 1 above.

thx

Original comment by downand...@gmail.com on 6 Nov 2010 at 1:08

GoogleCodeExporter commented 9 years ago
I experimented with some code to use a hidden checkbox for a toggle button:

http://code.google.com/r/msgilligan-iui-dev/source/detail?r=f56361e83e349c73518f
84ac46dfa523c1b8eaab&name=msgilligan-togglefixes

iui.js is changed, but the new CSS is inline in the toggles.html test file.

I'd like to see something similar to this solution as part of the 0.5 release.

Original comment by msgilli...@gmail.com on 18 Jan 2012 at 12:17

GoogleCodeExporter commented 9 years ago

Original comment by msgilli...@gmail.com on 18 Jan 2012 at 12:17

GoogleCodeExporter commented 9 years ago
So I was using the method from comment #5 and it all worked great until IOS 6.  
I've now found after upgrading to IOS 6 that when doing a submit it ALWAYS 
reports the toggle checkbox as being set regardless of what it actually is.

Thoughts???  Help! :)

Thanks.
Scott

Original comment by sbl...@litespeeddesign.com on 10 Jan 2013 at 10:32