Skip to Content
0

How can I add css style to controls sapui5? (ComboBox, TextArea)

Feb 08 at 12:30 PM

77

avatar image

Hello guys,

I'm trying to add CSS style to control. Whenever the value inside combobox is selected, the value submitted into the textarea.

I want to add css style for selected value into textarea.

Any ideas how can I do this?

regards,

Sergey

XML
<ComboBox showSecondaryValues="true" filterSecondaryValues="true" value="{/comboBoxValue}" selectedKey="{/comboBoxKey}" width="500px">
					<items>
						<core:Item text="" key=""/>
						<core:Item text="Orange" key="Orange"/>
						<core:Item text="Apple" key="Apple"/>
						<core:Item text="Apricot" key="Apricot"/>
						<core:Item text="Banana" key="Banana"/>
					</items>
				</ComboBox>
				<TextArea id="textarea" cols="60" value="{parts: [{path: '/comboBoxValue'}, {path: '/comboBoxKey'}], formatter: '.fnFormatter'}"
					width="100%"/>
JS
onInit: function() {


			// set explored app's demo model on this sample
			var oModel = new JSONModel(jQuery.sap.getModulePath("sap.ui.demo.mock", "/countriesCollection.json"));
			oModel.setProperty("/comboBoxValue", "");
			oModel.setProperty("/comboBoxKey", "");
			this.getView().setModel(oModel);
		},


		fnFormatter: function(text, key) {
			var sText = "";
			if (text && key) {
				sText += "Selected fruits: " + text;
			}


			return sText;
		}
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Sergio Guerrero Feb 08 at 01:32 PM
-1

Sergey,

i do not think you can add css to the text inside the text area. instead you could use an html control and you could use css / styles there instead

https://sapui5.hana.ondemand.com/#/entity/sap.ui.core.HTML

Share
10 |10000 characters needed characters left characters exceeded
Arjun Biswas Feb 20 at 05:59 AM
0

Hi Sergey Easen,

You can make use of the method addStyleClass(), and pass your css class as a string as parameter to the method, to set custom styles to your control.

Regards,

Arjun Biswas

Share
10 |10000 characters needed characters left characters exceeded
Hunter Young
Feb 28 at 06:23 AM
0

Hi Sergey,

All you need to do is add something like

this.byId('textarea').addStyleClass(text);

to your fnFormatter function and then add some custom CSS classes with the same names as the values in your ComboBox to your project.

Best Regards,

Hunter Young

Share
10 |10000 characters needed characters left characters exceeded