Hey, I return with another question =) simpler this time I h

A place for users and developers of the Xataface to discuss and receive support.

Postby Jason » Tue Oct 16, 2007 6:09 pm

how do I get the application_menu.html to read javascript thats in a tag and read the command
cuz I have it in there...when I go to my application it seems to do nothing...when I go to the application_menu.html page directly it does the onload command correctly.

Im trying basically to prefill a form element text field w/ the current date using some sort of scripting language and currently trying to do it with javascript
please let me know if you have any other ideas on how I could achieve this.
Thanks,
Jason
Jason
 
Posts: 3
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Wed Oct 17, 2007 10:17 pm

Sorry for the delay.

The best way to prefill an element is with the xxx__default() method.

e.g. if you want the firstname field to default to 'bob', you would implement:

function firstname__default(){ return 'bob';}

in the delegate class.

In response to javascript to be executed on load, there are lots of functions that are assigned to be performed onload, so you can't just say body.onload = myfunc().

You can still do this with javascript. My recommendation would be to:

1) define the javascript function that you want performed on load.
2) Call registerPloneFunction() to register your function to be called on load.

**NOTE** If javascript is placed in a template, you have to either:
a) Include it as an external file. e.g.
or
b) Wrap the javascript portions in {literal}{/literal} tags so that smarty will ignore the javascript.

e.g.

{literal}
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby Jason » Thu Oct 18, 2007 4:13 pm

hrm Im confused, I cant just prefill it with your first method because I need the date in the box to be the current day.
As far as the second half goes, can you give me any code to help me get started? like the structure of steps 1 and 2 you layed out.

here is what Im trying to achieve:

{literal}






{/literal}

how I do that above so plone does it for me? or with an external .js file

thanks =)
Jason
 
Posts: 3
Joined: Wed Dec 31, 1969 5:00 pm

Postby Jason » Thu Oct 18, 2007 4:18 pm

hrm Im confused, I cant just prefill it with your first method because I need the date in the box to be the current day.
As far as the second half goes, can you give me any code to help me get started? like the structure of steps 1 and 2 you layed out.

here is what Im trying to achieve:

{literal}






{/literal}

how I do that above so plone does it for me? or with an external .js file

thanks =)
Jason
 
Posts: 3
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Sun Oct 21, 2007 1:03 am

I cant just prefill it with your first method because I need the date in the box to be the current day.


No reason why you can't use the method I mentioned to show the current day.

e.g.
function xxx_default(){ return date('Y-m-d');}

The will return the current day.

As far as the second half goes, can you give me any code to help me get started?


Code: Select all
function setFieldDefaults(){
    document.getElementById('date').value = 'my default value';
    document.getElementById('otherField').value = 'my other default value';
}

// we want setFieldDefaults() to execute when the page is loaded so we register it:

registerPloneFunction(setFieldDefaults);


Just make sure that this appears in some section of javascript and it will run when the page is loaded.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby Jason1 » Mon Oct 29, 2007 2:36 pm

function xxx_default(){ return date('Y-m-d');}

can you give me an example of where I would put this code? to make it work for the page?? will do this do the same as autofilling the form field instead of having to do the javascript method?

Would it be as simple as just putting the element id into the xxx_default?
So would if the field id is startdate can I just put

function startdate_default(){ return date('Y-m-d');}

Where would I put the above code then....to make it work...
Thanks,
Jason
Jason1
 
Posts: 5
Joined: Mon Oct 29, 2007 2:33 pm

Postby shannah » Mon Oct 29, 2007 2:43 pm

Where would I put the above code then....to make it work...

You place the xxx_default() method in your delegate class.

You place the javascript into a javascript file.

There are many ways to include javascript in pages. One way is to insert it directly using a block.

See http://xataface.com/documentation/tutor ... ustomizing
for info on blocks and how they are used.

See http://xataface.com/documentation/how-t ... avascripts for information on how to include javascripts in your application.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 33 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved