Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ayo Adesina 430 posts 1023 karma points
    Oct 17, 2017 @ 10:01
    Ayo Adesina
    0

    Validation - Custom Section/Drop Down List

    Hi,

    I'm creating a custom section in the Umbraco Back office, in one of my views I have a drop down list.

    In my HTML view I rendering the drop down list like this:

    <umb-property property="vm.campaign.campaignTypePropertyEditor">
         <umb-editor model="vm.campaign.campaignTypePropertyEditor"</umb-editor>
     </umb-property>
    

    and vm.campaign.campaignTypePropertyEditor

    Is created like this:

                campaignViewModel.CampaignTypePropertyEditor = new UmbracoPropertyEditorViewModel()
                {
                    Editor = "Umbraco.DropDown",
                    Label = "Campaign Type",
                    Description = "Select campaign type.",
                    HideLabel = false,
                    View = "dropdown",
                    Alias = "campaign.campaignType",
                    Validation = new UmbracoPropertyEditorValidation() { Mandatory = "true", Pattern = "" },
                    Config = GetCampaignTypePropertyEditorConfig(),
                    Value = ((int)campaign.CampaignType).ToString()
                };
    

    This works, I have all my items showing up in my drop down list, but there is also a blank entry I want to make sure that if the user selects this, the form will be invalid.

    This works for text boxes:

    Validation = new UmbracoPropertyEditorValidation() { Mandatory = "true", Pattern = "" },
    

    What do I need to do to get this to work for drop downs?

  • Ayo Adesina 430 posts 1023 karma points
    Oct 18, 2017 @ 07:58
    Ayo Adesina
    0

    No Replies...... :-( Do I need more information in this question?

  • Ayo Adesina 430 posts 1023 karma points
    Oct 25, 2017 @ 08:50
    Ayo Adesina
    0

    This is starting to drive me crazy.........

    How the hell does umbraco do it? all I want to do is stop the user selecting the blank option in a drop down list.

    I'm reusing the dropdownlist property editor from umbraco. For all the other property editors this works, but not for a drop downlist.

    Looking at the built in umbraco dropdown.html there is no refrence to validation....

    SO how the hell does this work? ahhhhhhhh

    Umbraco I love you but sometimes........

  • Ravi Motha 290 posts 500 karma points MVP 7x c-trib
    Oct 25, 2017 @ 08:56
    Ravi Motha
    0

    Only just walked to this, but have you found a drop down that does what you want and pick that apart..

    Obviously on the controller you can do normal validation as a back stop ie check if the value blank and the return it as an error...

  • Ayo Adesina 430 posts 1023 karma points
    Oct 25, 2017 @ 09:29
    Ayo Adesina
    0

    I had a look at how it works in Umbraco, but its not Obvious or maybe I am looking in the wrong place.

    so this is the code for the built in dropdown.html in umbraco.

    <div ng-controller="Umbraco.PropertyEditors.DropdownController" ng-switch="model.config.multiple">
    
        <select name="dropDownList"
                class="umb-editor umb-dropdown"
                ng-switch-default
                ng-model="model.value"
                ng-options="item.id as item.value for item in model.config.items">
            <option></option>
        </select>
    
        <!--NOTE: This ng-switch is required because ng-multiple doesn't actually support dynamic bindings with multi-select lists -->
        <select name="dropDownList"
                class="umb-editor umb-dropdown"
                ng-switch-when="1"
                multiple
                ng-model="model.value"
                ng-options="item.id as item.value for item in model.config.items">
        </select>
    
    </div>
    

    I can not see any refrence to the validation object. - But if I look at DataPicker for example...

    <div class="umb-editor umb-datepicker" ng-controller="Umbraco.PropertyEditors.DatepickerController">
        <ng-form name="datePickerForm">
            <div class="input-append date datepicker" style="position: relative;" id="datepicker{{model.alias}}">
    
                <input name="datepicker" data-format="{{model.config.format}}" id="{{model.alias}}" type="text"
                       ng-model="datetimePickerValue"
                       ng-required="model.validation.mandatory"
                       val-server="value"
                       class="datepickerinput" />
    
                <span class="add-on">
                    <i class="icon-calendar"></i>
                </span>
    
            </div>
    
            <span class="help-inline" val-msg-for="datepicker" val-toggle-msg="required"><localize key="general_required">Required</localize></span>
            <span class="help-inline" val-msg-for="datepicker" val-toggle-msg="valServer">{{datePickerForm.datepicker.errorMsg}}</span>
            <span class="help-inline" val-msg-for="datepicker" val-toggle-msg="pickerError"><localize key="validation_invalidDate">Invalid date</localize></span>
    
            <p ng-if="model.config.offsetTime === '1' && serverTimeNeedsOffsetting && model.value" class="muted">
                <small><localize key="content_scheduledPublishServerTime">This translates to the following time on the server:</localize> {{serverTime}}</small><br/>
                <small><localize key="content_scheduledPublishDocumentation">What does this mean?</localize></small>
            </p>
            <p ng-show="hasDatetimePickerValue === true || datePickerForm.datepicker.$error.pickerError === true">
                <a href ng-click="clearDate()"><i class="icon-delete"></i><small><localize key="content_removeDate">Clear date</localize></small></a>
            </p>
    
        </ng-form>
    </div>
    

    You can see how it uses the validation object to make sure the feild is not blank. - So I would really like to know how umbraco does this.....

    enter image description here

    That is setting up the same control via the UI and ticking mandotory. I just want to copy the exact same thing

  • Ravi Motha 290 posts 500 karma points MVP 7x c-trib
    Oct 25, 2017 @ 09:28
    Ravi Motha
    0

    also what value is getting sent through to the controller if it is not blank.. it might be a whitespace and that maybe the issue

  • Ayo Adesina 430 posts 1023 karma points
    Oct 25, 2017 @ 09:34
    Ayo Adesina
    0

    This is the HTML, I am not adding the first one Value="" umbraco is doing that.... I want to stop them selecting the first blank option

    `<select name="dropDownList" class="umb-editor umb-dropdown ng-scope ng-valid ng-dirty" ng-switch-default="" ng-model="model.value" ng-options="item.id as item.value for item in model.config.items">
    
    <option value="" class=""></option>
    <option value="0" selected="selected">Raffle</option>
    <option value="1">Direct Win</option><option value="2">Headless (no campaign blocks allowed)</option>
    
    </select`>
    
  • Ravi Motha 290 posts 500 karma points MVP 7x c-trib
    Oct 25, 2017 @ 10:14
    Ravi Motha
    0

    so is the "empty" value coming through to the controller and what is it, and if you can see what it is then you can capture it, and error it..

  • Ayo Adesina 430 posts 1023 karma points
    Oct 25, 2017 @ 10:52
    Ayo Adesina
    0

    I could potentially do that, but that would involove me manually applying the CSS validation class to the drop down list too.

    So far I have been able to get all these controls to work exactly the same way do do in "Umbraco" (the content tree) I set the corret validation config and pow... everything works with out the need to do anything manually.

    When you create a drop down "normally" using doctypes, you can select mandatory check box and then if the user selects the blank record in the content tree the validation kicks in....

    I might have to do it manually, but there must be away to do it the way umbraco does I'm just not sure where to look other than the property editors HTML (dropdownlist.html) - but it looks like this is happening outside the control..........

    Do you get what I mean?

  • Ravi Motha 290 posts 500 karma points MVP 7x c-trib
    Oct 25, 2017 @ 12:47
    Ravi Motha
    0

    I think that's what I am trying get at. I want to see what is trying to do that validation maybe there is a bug when you apply a custom control .. it migt be worth doing an our umbraco trawl and or looking at the issues to see if this is a known thing.

Please Sign in or register to post replies

Write your reply to:

Draft