• Resolved metalhead

    (@aaronthomas1979)


    Hello,

    I need to change the format of the date field, so when users enter their date of birth, they can do MM-DD-YY

    I read about this discussion in another post, and the way to resolve it was to use this js code:

    jQuery(function($) {
    $(‘.bxcft-birthdate-month’).insertAfter($(‘.bxcft-birthdate-month’).parent().find(‘label’));
    });

    However, I do not know which file to add this code to. Can someone please tell me?

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author donmik

    (@atallos)

    You have to put in your template file overriding buddypress template file.

    There is an easier way with css. Maybe it works for you. Add the following code to your theme’s stylesheet:

    .bxcft-birthdate-month {
        float: left;
        margin-right: 5px;
    }
    Thread Starter metalhead

    (@aaronthomas1979)

    Thanks very much!

    I have a related follow up question:

    This is how I display my “City, State, Country” field in my members-loop.php file:

    echo bp_member_profile_data(‘field=City, State, Country’);

    How can I display age for my “Date of Birth” field? (Instead of displaying date of birth)

    Thanks in advance. You rock!

    Thread Starter metalhead

    (@aaronthomas1979)

    One other related question:

    When using this CSS method, it works great, but if you Tab to the date of birth field, the Day is still the first of the three boxes to have focus. Is there an easy way to place the focus on the Month box first? (I’d like to change the order of the focus to Month, then day, then year.)

    Plugin Author donmik

    (@atallos)

    Well, using css will not work if you want to support Tab navigation on the form. I’ve been thinking about a better way to add the js without overriding buddypress templates. Add the following code to your theme’s functions.php:

    add_action( 'bp_after_profile_edit_content', 'change_birthdate_display_js' );
    add_action( 'bp_after_register_page', 'change_birthdate_display_js' );
    /**
     * Change the birthdate field type display: month - day - year.
     * Uses:
     *  - 'bp_after_profile_edit_content' hook for edit profile form.
     *  - 'bp_after_register_page' hook for registration form.
     */
    function change_birthdate_display_js() {
        ?>
        <script>
            jQuery(function($) {
                if ($('.bxcft-birthdate-month').length > 0) {
                    $('.bxcft-birthdate-month').each(function() {
                        $(this).insertAfter($(this).parent().find('label'));
                    });
                }
            });
        </script>
        <?php
    }

    This code will use 2 hooks:

    • bp_after_profile_edit_content: For the edit profile form.
    • bp_after_register_page: For the registration form.

    I’ve modified my original javascript code because it was working only with one field. If you have more than one birthdate field, you will have problems. This code should work in any case I think.

    Plugin Author donmik

    (@atallos)

    To display the age inside the members loop, you cannot use right “bp_member_profile_data”. I will probably modify the result delivered by this method in future updates…

    Right now, you will need to use the following code:

    echo xprofile_get_field_data('Date of Birth', bp_get_member_user_id());

    Replace ‘Date of Birth’ with the name or your field or with the ID if you want without the quotes then. “bp_get_member_user_id()” will return the user id inside the members loop if you want to use this method outside the members loop you can use another function to get the user_id like bp_displayed_user_id() for the currently displayed user id or get_current_user_id() for the currently logged in user id.

    Thread Starter metalhead

    (@aaronthomas1979)

    Thanks VERY much Mr. Lopez! I owe you big time! I won’t forget this.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Change Birthday Format’ is closed to new replies.