calendar widget in delegate method

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

calendar widget in delegate method

Postby kevinwen » Sat Jan 07, 2012 3:52 pm

I want to get the HTML code of the calendar widget in the block__field_name_widget() in table's delegate class so it would have the same HTML output as defining the calendar in the fields.ini. How can I do that? Thanks.
kevinwen
 
Posts: 109
Joined: Mon Dec 28, 2009 3:44 pm

Re: calendar widget in delegate method

Postby shannah » Mon Jan 09, 2012 12:40 pm

I'm not sure I fully understand what you are trying to do. Can you explain a little more?
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: calendar widget in delegate method

Postby kevinwen » Tue Jan 10, 2012 12:11 am

Ok, I have a table with 2 columns(column_type, column_value) as following:

column_type enum('number', 'percentage', 'currency', 'date', 'text'),
column_value varchar(64);

The type of value of column_value depends on the value of column_type. For example, there is a record with 'number' in column_type, the value of column_value should be a number, even if it's stored as varchar. Same as for 'percentage' and 'currency'.

However, if the value of column_type is 'date', the value of column_value should look like '01/09/2012'. What I would like to do is to populate the calendar picker right next to the field 'column_value', if the value of column_type is 'date'. Therefore, create the widget for the column_value like:
Code: Select all
function block__column_value_widget() {
    $app =& Dataface_Application::getInstance();
    $record = $app->getRecord();
    echo '<input type="text" name="column_value" id="column_value" value="' . $record->val('column_value') . "' />
    if ($record->val('column_type') == 'date') {
        echo 'calendar picker is displayed here';
    }
}

So what is the javascript for the calendar picker or how do I accomplish the same goal as above you way?
kevinwen
 
Posts: 109
Joined: Mon Dec 28, 2009 3:44 pm

Re: calendar widget in delegate method

Postby shannah » Tue Jan 10, 2012 12:02 pm

I see. You're making a sort of meta schema layer. If I were you I'd probably approach this problem with pure javascript. Leave the field type as text, but use javascript to alternatively decorate the field depending on what the value of column_type is.

Most of the new widgets that are being developed work this way. They use a text field as a base and then are transformed with javascript into a different type of widget.

There are a ton of jQuery widgets that you can use that work this way. (they transform normal text fields into cool widgets).
Check out the datepicker widget Javascript file for a sample:
http://weblite.ca/svn/dataface/modules/ ... epicker.js

What this does is transform all text fields with the xf-datepicker CSS class into datepicker widgets.

The docs for the full datepicker module is at http://xataface.com/dox/modules/datepicker/latest
But this will only work with 2.0 which isn't finished/released yet. But there are some screenshots that give you an idea.

So in your case, you'd want to attach a listener to the column_type field that will automatically undecorate the column_value field then redecorate with another widget type.

Hope this helps.

-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 1 guest

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