+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Pre-selecting checkboxes

Pre-selecting checkboxes

12 posts, 0 answered
  1. Beth
    Beth avatar
    29 posts
    Registered:
    30 Oct 2013
    01 Apr 2014
    Link to this post

    I'm using the standard form tool to build a form that contains a list of products with checkboxes for users to check off which products they want more information on. I'd like to add the ability to have a checkbox preselected based on a url parameter. For example, if they were coming from a page about Product A, I could include ?product=A in the  url and have that product pre-selected. Is this possible with the standard form widget? And if so, how does one accomplish this? 

  2. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    07 Dec 2016
    04 Apr 2014
    Link to this post
    Hello Beth,

    You could get that url parameter by using jQuery on the Form page and then set the checkbox you want.

    More information about how to get the parameter could be found here or here.

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Beth
    Beth avatar
    29 posts
    Registered:
    30 Oct 2013
    04 Apr 2014 in reply to Svetoslav Manchev
    Link to this post

    How do I change the form field name/id to something that makes sense instead of the ones generated by Sitefinity? I've tried changing what's entered in the "DataFieldName" and "FieldName" fields of my checkbox in the Advanced pane of the checkbox widget to "product", but the code generated still has weird names and ids:

    id="contentPlaceholder_C003_ctl00_ctl00_C004_ctl00_ctl00_checkBoxes_1" type="checkbox" name="ctl00$contentPlaceholder$C003$ctl00$ctl00$C004$ctl00$ctl00$checkBoxes$1" value="Boat"

     This is my first time developing with anything .NET - I'm use to writing my own code and would have written something more like this instead of the mile long ID and name values that have been generated.

    id="productCheckbox" name="product" value="Boat"

     

     

  4. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    07 Dec 2016
    07 Apr 2014
    Link to this post
    Hi Beth,

    This change is not supported. Furthermore, such amendments of the ids is not advisable. as this might leads to unexpected behaviour of the form.

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  5. Beth
    Beth avatar
    29 posts
    Registered:
    30 Oct 2013
    07 Apr 2014 in reply to Svetoslav Manchev
    Link to this post

    It's sad to know that I'm stuck with such bloated nonsense for the form field names.

  6. Beth
    Beth avatar
    29 posts
    Registered:
    30 Oct 2013
    11 Apr 2014
    Link to this post

    Hello again! I've used jquery to parse my query string and can now select checkboxes, but am having a problem with drop downs. It seems that Sitefinity always wants to make one option selected and this overrides anything I do with jquery. The page will load, the drop box will switch to match the url parameter and then it will switch to the default value in sitefinity. Is there a way to NOT have a "selected" radio box checked in the admin?

     Thank you

  7. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    07 Dec 2016
    15 Apr 2014
    Link to this post
    Hello Beth,

    What is the scenario you have?
    I have tested the change of the dropdown value via the jQuery and that selected value is sent on submit without any issues:
    // get the first dropdown list in the form (just for the example)
    var dropdown = $('select')[0]
     
    // Set the new value
    dropdown.value = "My Choice 3"

    In case the value is not available in the dropdown list - the value is set as 'blank'.

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  8. Beth
    Beth avatar
    29 posts
    Registered:
    30 Oct 2013
    15 Apr 2014 in reply to Svetoslav Manchev
    Link to this post

    Thanks for the reply.

    I'm trying to get it to show selected on page load. It does, but then it changes to the value that's set as default via the form admin. I can't seem to create a select list without setting a default value.

     My Javascript:

    function getUrlParameter(sParam)
    {
        var sPageURL = window.location.search.substring(1);
        var sURLVariables = sPageURL.split('&');
        for (var i = 0; i < sURLVariables.length; i++)
        {
            var sParameterName = sURLVariables[i].split('=');
            if (sParameterName[0] == sParam)
            {
                return decodeURIComponent(sParameterName[1]);
            }
        }
    }
      var contactReason = getUrlParameter('reason');
     
    $("#contentPlaceholder_C001_ctl00_ctl00_C003_ctl00_ctl00_dropDown").val(contactReason);

    But that selection is being overwritten by Javascript that Sitefinity is dropping on the page:

    Sys.Application.add_init(function() {
        $create(Telerik.Sitefinity.Modules.Forms.Web.UI.Fields.FormDropDownList, {"_mutuallyExclusive":false,"_renderChoicesAs":1,"_returnValuesAlwaysInArray":false,"_selectedChoicesIndex":null,"choiceElement":$get("contentPlaceholder_C001_ctl00_ctl00_C003_ctl00_ctl00_dropDown"),"choices":[{"Text":"Individual Account","Value":"Individual Account","Description":null,"Enabled":false,"Selected":true},{"Text":"Business Account","Value":"Business Account","Description":null,"Enabled":false,"Selected":false},{"Text":"Auto Loan","Value":"Auto Loan","Description":null,"Enabled":false,"Selected":false},{"Text":"Home Loan","Value":"Home Loan","Description":null,"Enabled":false,"Selected":false},{"Text":"Home Improvement Loan","Value":"Home Improvement Loan","Description":null,"Enabled":false,"Selected":false},{"Text":"All Other Loans","Value":"All Other Loans","Description":null,"Enabled":false,"Selected":false},{"Text":"Investments","Value":"Investments","Description":null,"Enabled":false,"Selected":false},{"Text":"Insurance","Value":"Insurance","Description":null,"Enabled":false,"Selected":false},{"Text":"Employment Opportunities","Value":"Employment Opportunities","Description":null,"Enabled":false,"Selected":false},{"Text":"Other","Value":"Other","Description":null,"Enabled":false,"Selected":false}],"controlErrorCssClass":"sfErrorWrp","dataFieldName":"FormDropDownList_C003","dataFormatString":null,"defaultValue":["Individual Account"],"description":null,"descriptionElement":$get("contentPlaceholder_C001_ctl00_ctl00_C003_ctl00_ctl00_descriptionLabel"),"displayMode":1,"example":null,"exampleElement":$get("contentPlaceholder_C001_ctl00_ctl00_C003_ctl00_ctl00_exampleLabel"),"fieldName":"contactReason","title":"Reason for contact","titleElement":$get("contentPlaceholder_C001_ctl00_ctl00_C003_ctl00_ctl00_titleLabel_dropdown"),"validatorDefinition":"{\"AlphaNumericViolationMessage\":\"Non alphanumeric characters are not allowed.\",\"ComparingValidatorDefinitions\":[],\"CurrencyViolationMessage\":\"You have entered an invalid currency.\",\"EmailAddressViolationMessage\":\"You have entered an invalid email address.\",\"ExpectedFormat\":0,\"IntegerViolationMessage\":\"You have entered an invalid integer.\",\"InternetUrlViolationMessage\":\"You have entered an invalid URL.\",\"MaxLength\":0,\"MaxLengthViolationMessage\":\"Too long\",\"MaxValue\":null,\"MaxValueViolationMessage\":\"Too big\",\"MessageCssClass\":\"sfError\",\"MessageTagName\":\"div\",\"MinLength\":0,\"MinLengthViolationMessage\":\"Too short.\",\"MinValue\":null,\"MinValueViolationMessage\":\"Too small.\",\"NonAlphaNumericViolationMessage\":\"Alphanumeric characters are not allowed.\",\"NumericViolationMessage\":\"You have entered an invalid number.\",\"PercentageViolationMessage\":\"You have entered an invalid percentage.\",\"RegularExpression\":null,\"RegularExpressionSeparator\":null,\"RegularExpressionViolationMessage\":\"Invalid format\",\"Required\":null,\"RequiredViolationMessage\":\"Required field.\",\"ResourceClassId\":\"\",\"USSocialSecurityNumberViolationMessage\":\"You have entered an invalid US social security number.\",\"USZipCodeViolationMessage\":\"You have entered an invalid US ZIP code.\",\"ValidateIfInvisible\":true}","value":"Individual Account"}, null, null, $get("contentPlaceholder_C001_ctl00_ctl00_C003"));
    });

  9. Beth
    Beth avatar
    29 posts
    Registered:
    30 Oct 2013
    15 Apr 2014
    Link to this post

    I thought a clearer overview of what I'm trying to do might be helpful:

     I have a few simple forms that I'd like to use for a variety of situations. One is a contact form that asked users to put a contact subject via a drop down list, enter their name, email and then message. I'd like to simplify things for them by auto-selecting the subject based on the URL. For example, if they came to the form from our loan application, the subject "Loan Application" would be pre-selected on the drop drown. 

    I want to do something similar on another form that has a set of checkboxes for items they'd like more information about. Again, if they are coming from a page about X, I'd like checkbox X to be checked.

     I'm just trying to make it easier for our users and make the form input faster.

  10. Beth
    Beth avatar
    29 posts
    Registered:
    30 Oct 2013
    15 Apr 2014
    Link to this post

    Never mind, I got it sorted out. I would still like to know if one can make a drop down list without having a default value. Still haven't figured that out.

  11. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    07 Dec 2016
    16 Apr 2014
    Link to this post
    Hi Beth,

    This is the default behaviour of the drop-down form control. In case you need to customize it, you could create a custom Form Field Control where you could implement your own logic to cover your needs. 

    More information is available in that article.

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  12. Beth
    Beth avatar
    29 posts
    Registered:
    30 Oct 2013
    17 Apr 2014 in reply to Svetoslav Manchev
    Link to this post

    Thanks for the reply

12 posts, 0 answered