Venue can't be set as required

Home Forums Calendar Products Community Events Venue can't be set as required

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1146682
    Sean
    Participant

    This is in relation to this post, which covered the Organizer not being able to be set as required (Nico helped craft a solution and advised to start a new thread for the venue issue).

    If the Venue is set to be required (either by adding ‘venue’ to the required array or by setting each individual venue field to be required via a filter), no error message is returned if the fields are left blank (even though it says “(REQUIRED)” next to the Venue Details heading). Perhaps the solution for making specific Organizer fields required will help as a starting point for coming up with a fix to enabling specific Venue fields to be required?

    Thanks,
    Karly

    #1147396
    Nico
    Member

    Hi Karly,

    Glad to help you out on this one too! A team member assigned this ticket to himself but asked me for help so here we go again…


    /* Custom venue validation */
    function tribe_custom_venue_validation ( $valid, $submission, $class ) {

    /* If no saved venue and there's no new venue title add error message and prevent submit */
    if ( empty ( $submission['Venue']['VenueID'][0] ) && empty ( $submission['Venue']['Venue'] ) ) {
    $valid = false;

    $message = __( '%s is required', 'tribe-events-community' );
    $message = sprintf( $message, 'Venue');
    $class->add_message( $message, 'error' );
    }

    return $valid;
    }

    add_filter('tribe_community_events_validate_submission', 'tribe_custom_venue_validation', 10, 3);

    The code above should limit submission with no saved venue or without new venue name (if you want to validate some more fields let me know). The only limitation is that the venue field label won’t be shown in red if invalid, because the variable holding those values is not accessible outside the submission handler class. If this is vital we can find a hacky work around like setting a general class or inserting some css or js directly into the page, surely not the best but it will work for now.

    Please give this a try and let me know,
    Best,
    Nico

    #1147913
    Sean
    Participant

    Hi again Nico!

    Thanks for putting this snippet together. I tried it out and it works perfectly for requiring the Venue Name be required.

    The Venue field label not being shown in red isn’t ideal, but if it would require anything more than a simple fix, I don’t know if it’s worth the trouble.

    What I am hoping you can help with is getting a few additional fields of the Venue required. In addition to the Venue Name, we need the Address, City, State and Zip Code required. Would it be possible to add those to the snippet?

    Kind regards,
    Karly

    #1148402
    Nico
    Member

    Glad to her it’s working Karly! FOllowing your comments I updated the snippet:


    /* Custom venue validation */
    function tribe_custom_venue_validation ( $valid, $submission, $class ) {

    /* bail if a saved venue is selected */
    if ( !empty ( $submission['Venue']['VenueID'][0] ) ) return $valid;

    /* check that venue name, address, city, state and zip fields are not empty */
    if ( empty ( $submission['Venue']['Venue'] ) || empty ( $submission['Venue']['Address'] ) || empty ( $submission['Venue']['City'] ) || empty ( $submission['Venue']['Province'] ) || empty ( $submission['Venue']['Zip'] ) ) {

    $valid = false;

    /* Inject custom css to reproduce the error state */
    add_action('wp_head', function () { ?>

    <style>
    #event_tribe_venue h4 > label {
    color: red;
    font-weight: 700;
    }
    </style>

    <?php });

    $message = __( '%s is required', 'tribe-events-community' );
    $message = sprintf( $message, 'Venue');
    $class->add_message( $message, 'error' );
    }

    return $valid;
    }

    Please let me know if it works as expected now,
    Best,
    Nico

    #1148493
    Sean
    Participant

    Good evening Nico,

    Thanks for adding these additional Venue fields and setting the label to be red after the error message is returned. In my case I just needed to change the “Province” in the snippet to “State” so it would require the United States “State” field. The error message is now correctly shown when one or more of those fields are left blank or a saved Venue is not selected.

    Again, I really appreciate you coming up with a fix for making the Venue (and Organizer) required. If this knowledgebase article is updated with the respective snippets for making the Venue and Organizer required, I’m sure others would find them helpful as well.

    Thanks again and have a great weekend!
    Karly

    #1148821
    Nico
    Member

    Wooot! Glad to hear Karly 🙂

    I’ll make a note to update the Knowdledge base article temporarily until this is fixed in the plugin codebase and works as it did before.

    I’ll go ahead and close out this thread, but if you need help with anything else please don’t hesitate to create a new one and we will be happy to assist you.

    Best,
    Nico

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Venue can't be set as required’ is closed to new replies.