![]() |
simplest way to do it - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: simplest way to do it (/showthread.php?tid=49673) |
simplest way to do it - El Forum - 02-28-2012 [eluser]Hoopoe[/eluser] I have a form on the 4th tab (jQuery) If the inputs fail validation I want to reshow it etc. Reloading the view for the form page takes me to the default tab, not the 4th one. Could a knowledgeable person describe for me how it's possible to reload the page so the form tab is selected ? My hunch is to bung a flag variable into the $data array in the load view. Draft a basic jQuery script which hard codes the selection of the 4th tab. Then echo out that script iff the flag variable is not empty... I am sorry if this question has been dealt w before but i haven't spotted where. Tom simplest way to do it - El Forum - 02-28-2012 [eluser]CroNiX[/eluser] If you only have a form on that one tab, you can check for errors using validation_errors(). If it's not empty (there are errors), tell jQuery to open the 4th tab. simplest way to do it - El Forum - 02-28-2012 [eluser]Hoopoe[/eluser] Thank you. Isn't the validation done in PHP on the server ? If the validation fails (I use CI-form-validation) then how can the result of the failure be referenced by the jQuery which is run in the browser ? I understand how this can be done using uri-segments, but I am calling the form via load->view. simplest way to do it - El Forum - 02-28-2012 [eluser]CroNiX[/eluser] Yes, it's done on the server. I use a template system where I can set javascript variables in the head of my document from my controller. So, in my controller, I check to see if validation_errors() contains anything and I set a js variable to TRUE if it does, FALSE if it doesn't. Then in my javascript, it just checks to see if the javascript variable is TRUE, if it is it opens the correct tab. If not it just opens the first tab like normal. simplest way to do it - El Forum - 02-28-2012 [eluser]Hoopoe[/eluser] CroNIX, your answer is very clear. I get it. Thanks a lot. Tom simplest way to do it - El Forum - 02-28-2012 [eluser]Aken[/eluser] To keep JS out of your header, you could also just set a specific class somewhere in your HTML that your JS will look for. If it exists, show the 4th tab by default, yadda yadda. simplest way to do it - El Forum - 02-28-2012 [eluser]Hoopoe[/eluser] That is degenerate art but I like it. mmm so easy. |