cancel
Showing results for 
Search instead for 
Did you mean: 

How to change color of a placeholder of an input field in ui5?

Former Member
0 Kudos

Hi All,

We often get requirements from client where they want to highlight the placeholder of input field.

I have an input field. Its placeholder color has to be changed to 'RED' so that user understands that its a mandatory field.

Could you please help me out on how can i change this feature.

I have seen blog related to html5, but not sure in ui5 how to handle it.

Awaiting replies.

Thanks,

Zakeer

Accepted Solutions (0)

Answers (5)

Answers (5)

karthikarjun
Active Contributor
former_member182862
Active Contributor
0 Kudos

Hi

there are a few ways to do this.

Here they are

1. JS Bin - Collaborative JavaScript Debugging

2. JS Bin - Collaborative JavaScript Debugging

I prefer 2 because you can reuse  the control in many places and have the same behavior

Thanks

-D

antonette_oberholster
Active Contributor
0 Kudos

Hallo Zakeer

You can use the value state function in SAPUI5.

Example:

Field must be numeric:

//View:
tfdPreCalibration = new sap.ui.commons.TextField({
id : "PreCalibration",
required : true,
change : function() {
  if (this.getValue() === "") {
   this.setValueState(sap.ui.core.ValueState.Error);//red
  } else {
   this.setValueState(sap.ui.core.ValueState.None);//normal
  }
}
});

//Controller: (on submit)
var testPreCalibration = sap.ui.getCore().getControl("PreCalibration").getValue();
if ( ! sap.ui.controller(<mycontroller>).isNumberFieldValid(testPreCalibration) ){
sap.ui.getCore().getControl("PreCalibration").setValueState(sap.ui.core.ValueState.Error);
}

There is also a yellow warning state

Hope this helps

Antonette

saivellanki
Active Contributor
0 Kudos

Hi Zakeer,


Will this help? JS Bin - Collaborative JavaScript Debugging


Regards,

Sai Vellanki.

maartenf
Participant
0 Kudos

Hi Zakeerhusen,

This is possible using custom CSS so you'll have to add your own html classes to the input fields where you want to have this effect.

Good luck!

Best regards,

Maarten