0

Zend Dojo Decorators

Posted by Gabriel on Jul 22, 2009 in dojo, php, zend

I’ve been having some trouble getting zend decorators to change the way a form layout displays on the page, by default zend likes to display it’s forms like this

<form>
<dl>
<dt>Label</dt><dd><input type=…></dd>
<dt>Label</dt><dd><input type=…></dd>
<dt>Label</dt><dd><input type=…></dd>
</dl>
</form>

and I wished them to be more div-y.
Unfortunately due to the complex ways of them creating horizontal sliders this wasn’t usual, so I decided to settle for a table, tr and tds, because of the strange way we’re doing the form (we start with the form hidden and reveal each question as the previous one passes validation (zend’s validators for the appearence and some custom ones before revealing the next question, stored in a hidden field)) this was actually quite tricky, especially when we had questions that didn’t need answering, so they needed to pass validation before they were even focused on so that the next field would be revealed until the time that a required question was met. It would have been a lot easier to have all the voluntary questions in one block at the end or beginning but the order of the questions was important.

So in the way of the decorators we have
$decoratorsOpen = array(
‘DijitElement’,
‘Errors’,
array(array(‘data’ => ‘HtmlTag’), array(‘tag’ => ‘td’)),
array(‘Label’, array(‘tag’ => ‘td’)),
array(array(‘row’ => ‘HtmlTag’), array(‘tag’ => ‘tr’, ‘openOnly’=>’true’, ‘class’ => ‘hiddenToReveal’, ’style’ => ‘display:none;padding:auto;’, ‘id’ => $IDName.’TR’)),
);
Fairly easy, we ignore DijitElements (because they tend to be a bit complex for our generic decorator) and errors, we find the elements regarde as data and chuck em in a td, same with the labels, we then suround the group in a tr, but with ‘openOnly’=>’true’ this means the tr only gets open and we can tack some more elements into the same tr. Set the trs class, some styling and the id of the tr, this is what gets used to identify the element to be revealed.
And then we add in a hidden element that contains the validation regex and close the tags with a similar decorator except with ‘closeOnly’=>’true’.

After all that we define some js to check the current element (onfocus, onkeyup etc) and validate and then get all the elements of class hiddenToReveal, loop through till they find the element whos predecessor is the one we just validated and reveal it to the world! (dojo.fx.wipeIn ftw)

One of the noticable things about dojo is their lovely tooltips, unfortunately they don’t always work with each element, for example datetextbox extends validationtextbox, validationtextbox has a promptmessage method for doing the tooltip, datetextbox can use this method without Eclipse or PHP complaing, but it just doesn’t display the tooltip, so we have genrerate them seperatly and add them ignoring promptmessage.

This might break mvc but I’m not sure:

In the view
foreach( $this->TooltipArray as $elementId => $tt){
echo $this->tooltip(
$elementId.”TT”,
null,
array(‘connectId’ => $elementId, ‘label’ => $tt ));}
And all we do is pass it an array of ['elementId']=’tooltip’, the tooltip itself has an id elementIdTT, the tooltip is connected to elementId and the tooltip has the value \o/

Now I get the fun of doing serverside validation and playing with dojo.xhr to submit the data. :)

Tags: , , , ,

 
0

She lives!

Posted by Gabriel on Jul 21, 2009 in GoMAD thinking, dojo, linux, php, zend

I haven’t posted in a while, I’ve just started my University placement and am currently working for GoMAD thinking designing an online coaching tool using the Zend Framework and Dojo. It’s quite different learning to use php in a proper MVC way, even trickier learning to work with Zend to get around it’s interesting little foibles. I decided to resurrect this blog and use it as a kind of dev blog, charting the pitfalls and solutions I’ve encountered on my journey, I also plan to explain a bit more about the company and the location we’re working in.

We work currently on our own laptops that the company provides, we have stands to put them in and keyboards and mices to attach, no external monitors so I’m very glad I managed to get a new one with a decent screen, a toshiba Satellite Pro A300, it originally came with Windows Vista Business in and I’ve left that on here but I’ve also installed Ubuntu 9.04 which seems to be working well.

I’m developing using the latest eclipse from source for php developers and the standard php/Apache that comes on the Ubuntu repos (5.2.6 and 2.2.11)

I’m working with Gavin a fellow student from DMU and Antonios, a DMU PhD student working towards a doctorate in fuzzy logic style.

I’m currently working on a SMART goals defining webpage, generating questions from a db, using dojox.fx to hide and reveal questions as and when they become active. Having a little trouble with decorators at the moment and I’m waiting for a reply on nabble, Matthew Weier O’Phinney has helped me via nabble so far and hopefully we can get this sorted today.

I’m really enjoying working here so far, and learning to use Zend/MVC helps lots to keep me interested.

Tags: , , , , , ,

Copyright © 2010 Random Rantings of a Demented Mind All rights reserved. Theme by Laptop Geek.