Multiselect Checxbox values to Tags

This topic contains 6 replies, has 3 voices, and was last updated by  Neil Hall 7 years, 9 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #356529

    Neil Hall
    Buyer
    Post count: 83

    I have set up a Multiselect Checkbox in an Add listing form with about 20 options. What I am trying to do is for the options that the user selects by ticking, to automatically add the values to the Tag Keywords field (post_tags), when the ‘Please accept our terms and conditions’ checkbox (geodir_accept_term_condition) is ticked.

    I have managed to do a similar thing with other fields using jQuery in the following way, but these fields are text, which makes it easier. For example:-

    <script type="text/javascript">
    jQuery(document).ready(function() {
    if (jQuery('#post_city').length > 0 ) {
    jQuery(document).on('change', 'input[name=geodir_accept_term_condition]', function() {
    if (this.checked) {
    jQuery('#post_tags').val(jQuery('#post_city').val() + ',' +
    jQuery('#post_country').val() + ',' +
    jQuery('#post_title').val() );
    }
    });
    }
    else {
    jQuery(document).on('change', 'input[name=geodir_accept_term_condition]', function() { if (this.checked) {
    jQuery('#post_tags').val(jQuery('#post_title').val() );
    }
    });
    }
    });
    </script>
    

    When I set up the GeoDirectory Multi Select Field in the CPT settings the code generated is as follows. So what I am trying to do is for example if the user ticks the 1st and 2nd options the values “Action” and “ Animation” are then input in to the “post_title”

    HTML REMOVED FROM HERE AND PASTED IN REPLY BELOW

    I did find a jQuery code solution that may possibly work, but this relies on the “checkbox” being checked so the items can be filtered. Unfortunately when using the GeoDirectory code which is generated above when the box is ticked in the front end this does not change the status of the code to ‘checked’.

    So, What do I need to do is find a way of showing the individual checkbox’s as ‘checked’ Can someone suggest a way of doing this?

    Or alternatively is there another way of getting the selected values in the Tag Keyword box?

    #356556

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    I’ve flagged this for the developers. They’ll let you know asap.

    Please next time you paste code in the forum, make sure to wrap it in code tags (2nd button from the right.)

    The html was breaking the forum layout for this page so i had to copy it and paste it here:

    <div id="geodir_add_genre_row" class=" geodir_form_row clearfix gd-fieldset-details"><label>Additional genre</label> <input name="gd_field_geodir_add_genre" type="hidden" value="1" /> <ul class="gd_multi_choice">  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Action" /> Action</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Animation" /> Animation</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Comedy" /> Comedy</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Documentary" /> Documentary</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Family" /> Family</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Film-Noir" /> Film-Noir</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Horror" /> Horror</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Musical" /> Musical</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Romance" /> Romance</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Sport" /> Sport</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="War" /> War</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Adventure" /> Adventure</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Biography" /> Biography</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Crime" /> Crime</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Drama" /> Drama</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Fantasy" /> Fantasy</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="History" /> History</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Music" /> Music</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Mystery" /> Mystery</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Sci-Fi" /> Sci-Fi</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Thriller" /> Thriller</li>  	<li><input class="gd-checkbox" name="geodir_add_genre[]" type="checkbox" value="Western" /> Western</li> </ul> <span class="geodir_message_note">Select the additional genre</span>  </div>

    Thanks

    #356591

    Neil Hall
    Buyer
    Post count: 83

    Hi Paolo

    Sorry for the problem with the code, I did not realize.

    #356913

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Please see this example:
    https://jsfiddle.net/r12htn7c/

    Thanks,

    Stiofan

    #357825

    Neil Hall
    Buyer
    Post count: 83

    Hi Stiofan

    I have tried to use the jQuery example that you gave, but I can’t get it to work. I set up the

    <span id='output'>none</span>

    which display in the frontend as ‘none’.
    I am using the html that is automatically generated by Geodirectory for the multiselect checkbow which is listed above.
    I’ve used the JQuery in the example and tried different Id to #gd_field_geodir_add_genre, #geodir_add_genre_row, #geodir_add_genre and even #geodir_add_genre[] (which jQuery really does not like). I even tried using different classes, but the ‘option’ output does not change.

    With my limited knowledge it seems that within the code generated by Geodirectory there does not seem to be a name or Id I can tie into. And also when a checkbox is ticked it does not change the status in the same way the example you gave does.

    Are my assumptions correct?

    Best Regards
    Neil

    #359373

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi Neil,

    here is an updated one that uses a text input like post tags, hopefully you can get it from here:

    https://jsfiddle.net/r12htn7c/1/

    (it works for me)

    Stiofan

    #361360

    Neil Hall
    Buyer
    Post count: 83

    Hi Stiofan

    The jQuery example that you gave did not seem to work. I think the problem lies in the code that is automatically output when a Multiselect checkbox is generated in the Add Listing page. There does not seem to be anything that triggers the change. However, after a lot of playing about I came up with the following that worked for me

    
    
    <script type="text/javascript">
    		jQuery(document).ready(function() {
    		jQuery('.gd_multi_choice').on('change', function() {
    			        var selecttag = [];
            jQuery("input[name='geodir_add_genre[]']:checked").each( function (){
    			selecttag.push(jQuery(this).val());
    			        });
                                       jQuery('#post_tags').val(selecttag);
    });
    });
    		</script>
    

    If you have multiple CPT’s and therefore multiple ‘Add Listing’ pages then this will work on all of them as long as the ‘HTML variable name’ is the same.

Viewing 7 posts - 1 through 7 (of 7 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount