|
|
|
News id
|
72
|
Headline
|
Adding some text when no block/slot exists
|
Content
|
Sometimes you need to add some text to a certain template, but Xataface doesn't have the specific block or slot to use. For example, say you wanted to include some text underneath the password field in the login page for Xataface. You can't do this with blocks or slots since nothing exists underneath that field. You can however do a workaround by using javascript and the DOM concept. br /br /For example:br /br /blockquotebr /function block__after_login_form(){br /lt;script language=quot;javascriptquot;gt;lt;!--br /var div = document.createElement(#39;div#39;);br /div.className = 'formHelp';br /var text = document.createTextNode(#39;Please enter the correct password#39;);br /div.appendChild(text);br /br /document.getElementById(#39;Login-Password#39;).appendChild(div);br ///--gt;lt;/scriptgt;br /}br //blockquotebr /br /First thing to notice is we are using the block__after_login_form() which simply a block on that template. We are using it to include our javascript of interest. We could have actually used any block. br /br /blockquotevar div = document.createElement(#39;div#39;);/blockquotebr /br /The first thing we do is create a div element.br /br /blockquotediv.className = 'formHelp';/blockquotebr /br /Here are just giving it the css class name of formHelp which gives it a nice styling feel. This is the same style used for widget:description values.br /br /blockquotevar text = document.createTextNode(#39;Please enter the correct password#39;);/blockquotebr /br /And then we create a textnode which contains the text of interest.br /br /blockquotediv.appendChild(text);/blockquotebr /br /With out div element, we are appending the text node we just created to it.br /br /blockquotedocument.getElementById(#39;Login-Password#39;).appendChild(div);/blockquotebr /br /And finally we add our div element to our element of interest which happens to have the id of "Login-Password" This id has been assigned by Xataface itself.br /br /And if everything works out fine, then you should see the text appear below the password field!br /br /You can find more information about how to manipulate DOM structure using javascript a href="http://www.howtocreate.co.uk/tutorials/javascript/domstructure"here/a.
|
Image
|
(Empty)
|
Date posted
|
Wed Nov 12 18:01:00 2008
|
Posted by
|
noreply@blogger.com (Fong Chun Chan)
|
Status
|
Approved
|
Categories
|
Blog
|
Source id
|
Fong's Blog
|
Source url
|
http://fongxataface.blogspot.com/2008/11/adding-some-text-when-no-blockslot.html
|
|
|