How to display a text in different font styles ???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2022 11:00 AM
Hi Team,
I have a written a client script to pre fill the text for few fields like the below script when we onload the change form.
Onload Client script :
var shortdescription = "A short summary of what will be done under this change record :";
var description = "List the planned activities (high level) per team to describe what will be done as part of this change record :";
g_form.setValue("short_description",shortdescription);
var sd = g_form.getControl('short_description');
sd.style.color = 'black';
sd.style.fontStyle = 'italic';
g_form.setValue("description",description);
var des = g_form.getControl('description');
des.style.color = 'black';
des.style.fontStyle = 'italic';
Result : The above script is working fine but when we enter any text on the form, it should display normal text not with italic font style. Can any one guide me??
for example : suppose on change form, automatically populate this info in shortdescription field value "A short summary of what will be done under this change record :" but when we enter additional information for this field it should be in normal style text not in italic style
Only this portion should be in italic font sytle : A short summary of what will be done under this change record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2022 06:44 PM
You should be adding the text as placeholder attribute. You can separately apply styles to it. Something like:
function onLoad () {
var config = {
'short_description': 'Enter a short summary of what will be done under this change record',
'description': 'Enter the list of planned activities (high level) per team to describe what will be done as part of this change record',
};
// This is not necessary if the script is configured not to be isolated
var jQuery = new Function('return jQuery;')();
getMessage(Object.keys(config).reduce(extractTextToTranslate(config), []), applyPlaceholders(config));
function extractTextToTranslate (source) {
return function (messages, key) {
return messages.push(source[key]), messages;
};
}
function applyPlaceholders (config) {
return function (messages) {
Object.keys(config)
.map(getControlAndMessage(config, messages))
.map(addPlaceholder(config, messages))
.map(addPlaceholderStyle());
};
}
function getControlAndMessage (config, messages) {
return function (fieldName) {
return { 'control': g_form.getControl(fieldName), 'message': messages[config[fieldName]], };
};
}
function addPlaceholder () {
return function (controlAndMessage) {
jQuery(controlAndMessage.control)
.attr('placeholder', controlAndMessage.message);
return controlAndMessage.control;
};
}
function addPlaceholderStyle () {
return function (control) {
jQuery('head')
.prepend(getStyle(control.id));
return control;
};
}
function getStyle (id) {
var css = '*[id="element.' + id + '"] .form-control::placeholder { background-color: #f0e0e0; color: red; font-style: italic; };';
return jQuery('<style>')
.text(css);
}
}
The Client Script configuration:
The result is:
And when text is added:
This should give you a head start.
I suppose you can define the desired CSS by modifying function getStyle
. But making placeholder text black (the same as regular input) is not a good idea. Placeholder text should be different from regular text - I can tell that even as a regular web consumer. It is frustrating when one cannot outright tell if something is already entered text or just a placeholder. I would actually leave the default that come with the browser. You don't have to worry about dark OS/browser themes vs. light OS/browser themes and support for those.
Also one can easily add other fields by customizing the config
object. However do note that composite fields will not work. For that additional functions need to be defined, ones that detect that something is a composite field and return the proper display control.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2022 07:33 AM
Hi Jones,
Thanks for your reply,
I tried with your script, it is displaying this info ("A short summary of what will be done under this change record :) in Red color in short description field
but when i type any text in the field, the above info is clearing. That i dont want.
This Info should be in Italic font style " A short summary of what will be done under this change record :) in Red color in short description field " and this info should not clear. but when we type any text after this info that should be in Normal text "
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2022 02:40 PM
OK, I totally misunderstood the requirements. But what you ask for is not possible. A single or multi line text is of kind of input that does not allow formatting parts of their content. It's all or nothing.
In theory there is the possibility to develop some custom editor that allowed such a functionality, a composite field consisting of two fields: one for the original text and another for the user input. But it is not an easy task, it involves UI Macros and Jelly. I totally not recommend it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 06:34 AM
Thanks for your help Janos