Skip to Content

Unable to set value as null to smart field in SAPUI5

Dear experts,

I have used a smart field inside a Simple Form in a dialog fragment and the entity set was also bound correctly , F4 help is also working fine. But I am trying to clear the value every time I opens the dialog fragment, but the value is never cleared from the input area.

Can some body help me if there is any work around for this issue.

Controller Code:

forwardWrkItem: function(oEvt){
			var oView = this.getView();
			oView.setBusy(true);
			if(!this.fwdWrkItmDialog){
				this.fwdWrkItmDialog = sap.ui.xmlfragment(this.getView().getId(),"com.myinbox.view.ForwardWrkItm",this);
				this.getView().addDependent(this.fwdWrkItmDialog);
			}
			this.fwdWrkItmDialog.open();
			this.byId("fwdUserId").setValue(null);
			oView.setBusy(false);
		},
Fragment Code: 

<core:FragmentDefinition xmlns="sap.m"
	xmlns:smartFilterBar="sap.ui.comp.smartfilterbar"
	xmlns:smartField="sap.ui.comp.smartfield"
	xmlns:app="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1"
	xmlns:l="sap.ui.layout" xmlns:f="sap.ui.layout.form"
	xmlns:ui="sap.ui.table" xmlns:core="sap.ui.core">


	<Dialog width="auto" noDataText="{i18n>categoryNoData}">
		<customHeader>
			<Bar>
				<contentMiddle>
					<Label text="{i18n>FwdWrkItms}"
						class="sapUiTinyMarginBeginEnd" />
				</contentMiddle>
			</Bar>
		</customHeader>
		<content>
			<VBox class="sapUiTinyMarginBeginEnd">
				<Label text="{myinbox>/DetailViewData/Subject}" />
				<Text text="{i18n>FwdDlgItmHdrTxt}" level="H2" />
				<f:SimpleForm editable="true"
					layout="ResponsiveGridLayout" class="sapUiNoMargin">
					<f:content>
						<smartField:SmartLabel labelFor="fwdUserId"
							class="sapUiNoMargin">
							<smartField:layoutData>
								<l:GridData spanL="2" spanM="2" spanS="2" />
							</smartField:layoutData>
						</smartField:SmartLabel>
						<smartField:SmartField value="{bname}"
							id="fwdUserId" entitySet="ZC_USER_F4HELP">
							<smartField:layoutData>
								<l:GridData spanL="6" spanM="6" spanS="6" />
							</smartField:layoutData>
						</smartField:SmartField>
					</f:content>
				</f:SimpleForm>
			</VBox>
		</content>


		<buttons>
			<Button id="fwdDialogOk" text="{i18n>Ok}"
				press="handleForwardToUser" type="Emphasized" />
			<Button id="fwdDCancel" text="{i18n>Cancel}"
				press="closeFwdDialog" type="Emphasized" />
		</buttons>
	</Dialog>


</core:FragmentDefinition>

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Feb 09 at 06:37 PM

    clearing the model value will do the job.

    accessing ui element usually is a bad idea.

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 10 at 07:36 AM

    Hi Jun Wu,

    I was not storing the value which is entered in the input area in any of the model. And values for my smart field are coming based on annotations from CDS Views.

    So is there any alternate way to clear the entered value from Smart field.

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 10 at 09:09 PM

    Hi,

    according to the documentation, setValue(null) restore the default value (https://sapui5.hana.ondemand.com/#/api/sap.ui.comp.smartfield.SmartField/methods/setValue).

    Maybe you could try this.byId("fwdUserId").setValue("");

    I hope it's help

    regards

    Fabrice

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 12 at 06:12 AM

    Is your field is nullable in the metadata, if no make it nullable ?

    regards,

    Joseph

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 20 at 10:24 AM

    I found a solution about my case:

    I had to go to the aggregation content of the smart Field in order to reach the input:

    .getAggregation("_content")

    Then you can access to the value and setter aswell

    Hope it helps!

    Best regards

    Add comment
    10|10000 characters needed characters exceeded