-- dele454 <[email protected]> wrote
(on Tuesday, 23 December 2008, 04:17 AM -0800):
> Hi Matthew,
>
> Thanks for your reply. The following are the snippets you asked for:
>
>
> BOOTSTRAP:
>
> public static function setupView()
> {
> ...
>
> $view->addHelperPath('Zend/Dojo/View/Helper/',
> 'Zend_Dojo_View_Helper');
First off, it's much easier to use the following construct to set the
helper paths:
Zend_Dojo::enableView($view);
> ...
> }
>
> LAYOUT SCRIPT
>
> ...
>
>
> <?php
>
> if ($this->dojo()->isEnabled()){
>
> $this->dojo()->setLocalPath('../../../../../../../js/dojo/dojo.js')
Second, the localPath should be relative to the document root, not the
layout script.
>
> ->addStyleSheetModule('dijit.themes.tundra')
>
> ->requireModule('dijit.form.ValidationTextBox')
>
> ->requireModule('dijit.form.Textarea')
Third, normally, you should let the view helpers and form elements
generate the dojo.require statements, instead of doing it manually. More
on that below.
>
> ->setDjConfigOption('parseOnLoad', true);
>
>
>
> echo $this->dojo();
> }
> ?>
>
> </head>
> <body class="tundra">
>
> input
> type="text"
> id="firstName"
> size="20"
> dojoType="dijit.form.ValidationTextBox"
> required="true"
> propercase="true"
> promptMessage="Enter first name."
> invalidMessage="First name is required."
> trim="true"
> onchange="userNameOnChange()"
>
> />
>
> <?= $this->validationTextBox(
> 'firstname',
> 'Start writing here...',
> array('required' => true,
> 'propercase' => true,
> 'promptMessage' => 'Enter first name',
> 'invalidMessage' => 'First name is required'),
> array('size' => '20')
>
> );?>
>
> ...
>
> I think that is about it. Thanks for all your help. Much appreciated! I dont
> have the line Zend_Dojo_View_Helper_Dojo::setUseDeclarative(); in my codes
> but the declarative still works.
Okay, I see what's going on.
In the first case, you're actually creating declarative markup
*manually* -- not using the validationTextBox view helper. This works
for several reasons:
* You've manually specified the dojo modules you need
* You've set the parseOnLoad djConfig option
Normally when using Zend Framework with Dojo, you'll use view helpers or
form elements to generate the dojo.require statements and to generate
your markup, even when using declarative generation. You could have
written the first case as follows:
<?= $this->validationTextBox(
'firstName',
'',
array(
'required' => true,
'propercase' => true,
'promptMessage' => 'Enter first name.',
'invalidMessage' => 'First name is required.',
'trim' => true,
'onchange' => 'userNameOnChange()',
),
array('size' => 20)
) ?>
and, if you'd told the dojo view helper to use declarative markup, it
would have rendered the same.
In the second case, you're using the view helper, which, since you have
not told the dojo view helper to use declarative markup when generating
the dijit, generates the dijit programmatically. The problem is because
you're doing it in the *same* view script in which you echo the dojo view
helper.
The dojo() view helper must be rendered *AFTER* all other calls to dojo
or dijit view helpers. It can only render and generate based on what it
has been provided -- and calls made *after* it has been rendered won't
have been aggregated yet. This is particularly important when using
programmatic generation as this technique generates javascript artifacts
which the dojo view helper aggregates.
The solution to this is to capture your content that utilizes dijits
*prior* to calling the dojo() view helper. You can do this earlier in
the layout script:
<? $content = $this->validationTextBox(
'firstname',
'Start writing here...',
array('required' => true,
'propercase' => true,
'promptMessage' => 'Enter first name',
'invalidMessage' => 'First name is required'),
array('size' => '20')
); ?>
(head and other html..)
<?= $content?>
(continue...)
--
Matthew Weier O'Phinney
Software Architect | [email protected]
Zend Framework | http://framework.zend.com/