1
votes

I have a smartfield that has a value-list annotation. I would like it to behave such that text input is disabled for the field so the user is forced to open the value help when he clicks on the field, and select from a valid list - much like the valueHelpOnly property of sap.m.Input. I was looking for a similar property for smartfield but there isn't seem to be one?

If there's no standard property for this, what's the best way to validate input vs valid value help values for smartfields? Thanks in advance.

enter image description here

3
You can add the disabled property in the input - inizio

3 Answers

0
votes

I have a work around, if any one has a better solution then kindly suggest me

  • Add a class to you SmartField and using the class get the ID and add disabled attribute to the SmartField input tag

var sSmrtFldId = "#" + jQuery(".CustomSmrtFldClass").attr("id") + ".sapMInputBaseInner"; jQuery(sSmrtFldId).attr("disabled ", true);

0
votes

You have to use the Event innerControlsCreated of SmartField, then check if is a Input and call the method setValueHelpOnly(true)

onInnerControlsCreated: function (oEvent){
   oEvent.getParameters()[0].setValueHelpOnly(true);
}

Note: This code is a sample, you need to check if is a Input and avoid hard code the index access on the array of parameters.

0
votes

You need to do the following steps. Assume you defined the SmartField like this:

<smartField:SmartField value="{XXX}" textInEditModeSource="ValueList" innerControlsCreated="onControlCreated">
    <smartField:configuration>
        <smartField:Configuration preventInitialDataFetchInValueHelpDialog="false" displayBehaviour="idAndDescription"/>
    </smartField:configuration>
</smartField:SmartField>

Of course you have defined the needed annotation that shows the value list itesm. Something like this:

<Annotations Target="Metadata.YourEntityName/XXX">
    <Annotation Term="Common.Text" Path="Planttxt">
        <Annotation Term="UI.TextArrangement" EnumMember="UI.TextArrangementType/TextLast"/>
    </Annotation>
    <Annotation Term="Common.ValueListWithFixedValues" Bool="false"/>
    <Annotation Term="Common.ValueList">
        <Record>
            <PropertyValue Property="CollectionPath" String="XxxSet"/>
            <PropertyValue Property="Parameters">
                <Collection>
                    <Record Type="Common.ValueListParameterInOut">
                        <PropertyValue Property="LocalDataProperty" PropertyPath="XXX"/>
                        <PropertyValue Property="ValueListProperty" String="Id"/>
                    </Record>
                    <Record Type="Common.ValueListParameterDisplayOnly">
                        <PropertyValue Property="ValueListProperty" String="Name"/>
                    </Record>
                </Collection>
            </PropertyValue>
        </Record>
    </Annotation>
</Annotations>

We defined a innerControlsCreated="onControlCreated" handler, we need to provide the code for that in related controller:

/** 
* event fired by innerControlsCreated of SmartField
* @param {sap.ui.base.Event} oEvent pattern match event
*/
onControlCreated: function (oEvent) {
    if (oEvent.getParameters()[0] instanceof sap.m.Input && oEvent.getParameters()[0].getShowValueHelp()) {
        // set ValueHelpOnly for Inputs with ValueHelp
        oEvent.getParameters()[0].setValueHelpOnly(true);
    }
},