Skip to:
Content
Pages
Categories
Search
Top
Bottom

Date selector (datebox) control doesn’t allow future dates

Viewing 6 replies - 1 through 6 (of 6 total)
  • Perhaps I need to elaborate on this issue by way of a bump!

    I’d really appreciate it if anyone can help. I need to be able to change the dates that display in the date selector control in a customised Profile, e.g. to show this year and future years 2010, 2011, 2012, rather than previous years.

    Any pointers greatly appreciated.


    r-a-y
    Keymaster

    @r-a-y

    You can apply a filter to ‘bp_get_the_profile_field_datebox’ to add extra years:

    `apply_filters( ‘bp_get_the_profile_field_datebox’, $html, $day, $month, $year, $default_select );`

    Find the bp_get_the_profile_field_options() function in /buddypress/bp-xprofile/bp-xprofile-templatetags.php where this filter is defined, so you’ll have a better idea of how to override it.

    Some sample code that you can add to your theme’s functions.php:
    `function my_year_field ($html, $day, $month, $year, $default_select ) {
    // your code to override the year field
    }
    add_filter( ‘bp_get_the_profile_field_datebox’, ‘my_year_field’, 10, 5 );
    `

    Thanks r-a-y
    Sorry I’m new to this side of things.
    I’m taking your sample code and trying to add it to functions.php in my theme.
    I thought I need to take the apply_filters line and add it where the comment is? But that breaks everything. I’m unclear how/when to replace the $variables with actual values?
    Is it possible to give me the sample code complete with variables filled in so that the dateboxes all show the current year and an additional three years ahead. I.e. right now they’d show 2010, 2011, 2012, 2013?

    If you can submit this as an enhancement on https://trac.buddypress.org/, we can fix this in core.

    Thanks Paul – I have duly raised a ticket https://trac.buddypress.org/ticket/2946
    I am not a developer and hadn’t thought of this.
    My own problem is urgent and if in the meantime anyone could provide the line or two of necessary sample code exactly as required for the functions.php I’d really appreciate it. It’s for a site at http://resolution-revolution.org.uk and being unable to set deadlines after 31 Dec 2010 is causing us a big headache! Thank you


    r-a-y
    Keymaster

    @r-a-y

    There’s a bug in the ‘bp_get_the_profile_field_datebox’ that’s preventing overriding the date field.
    See – https://trac.buddypress.org/ticket/2947.

    @bobsie – To override the year value temporarily, you’ll need to patch /buddypress/bp-xprofile/bp-xprofile-templatetags.php:
    https://trac.buddypress.org/attachment/ticket/2947/2947.001.patch (only lines 457-534 are important).

    Once you’ve made those changes, add the following to your theme’s functions.php:

    `
    function my_datebox_field ($html, $type, $day, $month, $year, $default_select ) {

    // change your max year here
    $year_max = 2013;

    /* Check for updated posted values, but errors preventing them from being saved first time */
    if ( !empty( $_POST ) ) {
    if ( $day != $_POST )
    $day = $_POST;
    }

    if ( !empty( $_POST ) ) {
    if ( $month != $_POST )
    $month = $_POST;
    }

    if ( !empty( $_POST ) ) {
    if ( $year != date( “j”, $_POST ) )
    $year = $_POST;
    }

    $html = ”;

    switch ( $type ) {
    case ‘day’:
    $html .= ‘–‘;

    for ( $i = 1; $i < 32; $i++ ) {
    if ( $day == $i ) {
    $selected = ‘ selected = “selected”‘;
    } else {
    $selected = ”;
    }
    $html .= ” . $i . ”;
    }
    break;

    case ‘month’:
    $eng_months = array( ‘January’, ‘February’, ‘March’, ‘April’, ‘May’, ‘June’, ‘July’, ‘August’, ‘September’, ‘October’, ‘November’, ‘December’ );

    $months = array( __( ‘January’, ‘buddypress’ ), __( ‘February’, ‘buddypress’ ), __( ‘March’, ‘buddypress’ ),
    __( ‘April’, ‘buddypress’ ), __( ‘May’, ‘buddypress’ ), __( ‘June’, ‘buddypress’ ),
    __( ‘July’, ‘buddypress’ ), __( ‘August’, ‘buddypress’ ), __( ‘September’, ‘buddypress’ ),
    __( ‘October’, ‘buddypress’ ), __( ‘November’, ‘buddypress’ ), __( ‘December’, ‘buddypress’ )
    );

    $html .= ‘


    ‘;

    for ( $i = 0; $i < 12; $i++ ) {
    if ( $month == $eng_months[$i] ) {
    $selected = ‘ selected = “selected”‘;
    } else {
    $selected = ”;
    }

    $html .= ” . $months[$i] . ”;
    }
    break;

    case ‘year’:
    $html .= ‘—-‘;

    for ( $i = $year_max; $i > 1899; $i– ) {
    if ( $year == $i ) {
    $selected = ‘ selected = “selected”‘;
    } else {
    $selected = ”;
    }

    $html .= ” . $i . ”;
    }
    break;
    }

    return $html;
    }
    add_filter( ‘bp_get_the_profile_field_datebox’, ‘my_datebox_field’, 10, 6 );
    `

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Date selector (datebox) control doesn’t allow future dates’ is closed to new replies.
Skip to toolbar