How can I get the element corresponding to the dataproviderid passed as an argument to my function?
My field-element has a property editable, I want to make the editable fields a different color. Now I’m trying to use the same text for dataproviderId and name of the field but that is not always possible (for example where dataproviderid is in a relation to another table).
Also I can put a dataproviderid multiple times on a table form, one time editable, and the other time not. (don’t know a reason to do this, but it is possible…)
As far as I know this information is not available at the arguments that Servoy pass by default.
A workable way could be to loop through all your elements and store the elements as value of a dataprovider in an object (store object in a global var).
If you test for the existance of the form elements in an object, this loop only has to be done at first time show of the specific form…
So the object could look like this (where ‘myObject’ is the global var):
myObject = new Object();
myObject[_form] = new Object();
myObject[_form][_dpId] = _elementname;
of course the 3rd line should be part of a loop.
Hope this can help you.
Michel,
Do you want all editable elements have a different color or only the one selected?
For the first option, you can also link a different style class to that element. This you can do at design time (Servoy 3/4/5)
Second you could on startup of your application, check all elements on all forms if it is editable using the SolutionModel and, in case it is editable, set that style class or set the background/foreground color or borders. You need Servoy 4/5 for that.
In case you want only the selected element, you can use in Servoy 5 the onElementFocusGained/Lost() event on the form.
Will this help?
Martin
Thans guys. Although I would rather have had a parameter that would contain the element this is not a bad work-around.
This is the code in the onshow method:
var editableFields = new Object();
if (firstShow) {
var myForm = solutionModel.getForm(_form)
if (myForm.view == JSForm.LOCKED_TABLE_VIEW) {
for (_e in forms[_form].elements) {
if (forms[_form].elements[_e].editable == true) {
var _dp = forms[_form].elements[_e].getDataProviderID()
if (!globals.editableFields[_form]) {
globals.editableFields[_form] = new Object()
}
globals.editableFields[_form][_dp] = _e
}
}
}
}
and this is the code in the rowBGColorCalculation method:
if(_isSelected) {
if (forms[_form_name].controller.readOnly == true) {
return globals.SELECTED_ROW_COLOR
}
else if (globals.editableFields[_form_name] &&
globals.editableFields[_form_name][_dataproviderid] &&
forms[_form_name].elements[globals.editableFields[_form_name][_dataproviderid]] &&
forms[_form_name].elements[globals.editableFields[_form_name][_dataproviderid]].editable == true) {
return globals.EDITABLE_FIELD_COLOR
}
else {
return globals.EDITED_ROW_COLOR
}
}
It surprises me that this works.
The rowBGColorCalculation is designed to show the whole record in some color.
How do you determine the _dataproviderid in this method. Is there some loop?
This suggests that the rowBGColorCalculation is called for each element on the form.
I’m not sure about that.
What you’ve done in the onShow, shouldn’t that be in an onLoad?
It is called for every field in every row (the name is incorrect, it should be fieldBGColorCalculation).
Filling of the global object is only done the first time that onShow is called (first parameter in onShow method).
martinh:
The rowBGColorCalculation is designed to show the whole record in some color.
No longer since 4.0 if I’m not mistaken…
@Michel: this is exactly what I had in mind… it’s a workaround, but I guess you won’t notice any difference in speed!
michel:
It is called for every field in every row (the name is incorrect, it should be fieldBGColorCalculation).
This is new for me. Maybe it is new functionality in Servoy 5 because with previous version I had to create a HTML-field if I wanted to have some fields in a record having a separate color.
And that was only possible for non-editable fields.
What you describe now looks indeed more as fieldBGColorCalculation.
In that case I would expect that the JSEvent object is given as argument and the JSEvent object would have a reference to your element
I did some search on the internet and indeed I’ve found something similar:
http://www.servoyguy.com/code_repository/column_calculations/row_background_color
That would be nice getting a JSEvent object! Hope Servoy is listening…
The example is similar yes, we also implemented the alternating rows.
@Marc: No, it’s not much work and it’s not a big problem because we have a standard onShow method that almost all the forms call.
michel:
Hope Servoy is listening…
Always… it’s the Servoy forum
Ofcourse we are here
You’ll never get a JSEvent in the rowBGColorCalculation, because the triggering of the calculation is not based on a user triggered event directly.
The arguments send into the rowBGColorCalculation can be easily seen of you create the calculation/global method through the property editor for the form on which you want the rowBGColorCalculation. Servoy will automatically create the function object with all the proper parameters and also some nice JSDoc on top of it with additional information.
@martin: Those features were added long time ago…
Paul
pbakker:
@martin: Those features were added long time ago…Paul
We are from Belgium. It takes some more time
pbakker:
You’ll never get a JSEvent in the rowBGColorCalculation, because the triggering of the calculation is not based on a user triggered event directly.
Why do we get an event form onLoad and onUnload then? The first one can be seen as indirectly triggered by a user but the second one can occur at any moment.
pbakker:
You’ll never get a JSEvent in the rowBGColorCalculation, because the triggering of the calculation is not based on a user triggered event directly.
It would be nice to get a JSEvent or some other mechanism to target the row because we had a case where we wanted to grey out certain rows to signify to the user that they did not have access to certain records. Information they had access to would appear in a different fgcolor/bgcolor. Since we couldn’t target the form and elements directly because of the lack of a JSEvent, we had to use a table calculation instead that would return the value as well as html with the font color embedded in it.
function rowFGColorRCS(_value) {
var _access = (globals.svy_utl_isValueInArrayNumber(globals.user, _accessFK) < 0);
if (_access) {
return '<html><body><font color="#696969">'+_value+'</font></body></html>';
} else {
return '<html><body><font color="black">'+_value+'</font></body></html>';
}
}
@michel: ok, maybe not the best comparison. Bottom line is that sending in the elementName is not supported, because that would lead to developers using it it reference the actual element from within the calculation/global method and that is not supported (for technically valid reasons)
@bobbydtma: I think you’re mixing up 2 things: getting a JSEvent would not make any difference in being able to set the foreground color.
We are investigating how to provide developers with even easier control over the styling of elements/formatting of data. Please make sure your wishes are heard by discussing it on this forum and creating a resulting feature requests in our support system.
Paul
pbakker:
@michel: ok, maybe not the best comparison. Bottom line is that sending in the elementName is not supported, because that would lead to developers using it it reference the actual element from within the calculation/global method and that is not supported (for technically valid reasons)@bobbydtma: I think you’re mixing up 2 things: getting a JSEvent would not make any difference in being able to set the foreground color.
We are investigating how to provide developers with even easier control over the styling of elements/formatting of data. Please make sure your wishes are heard by discussing it on this forum and creating a resulting feature requests in our support system.
Paul
Could it be an option to have both rowBGColorCalculation and fieldBGColorCalculation , because when you want to only to show the whole row in a certain color, now it looks like the same method is called x-times (for all fields)
Maybe keep the rowBGColorCalculation as it was before and add a fieldBGColorCalculation (or elementBGColorCalculation is maybe a better name)
As the new behavior is already there, we will not revert to old behavior, as that would break existing implementation and that is not something we want to do.
Paul