The following page is not behaving the way I understand it. I thought that after I updated the First_Name__c field in the UI that the ‘Name’ field should update as well. However, that is not happening. Instead its only updating when the page loads, or when I click on Save or even cancel. When I inspect the element, I want to see the Snippet running but it is not. I don’t see any of the Console.log() messages I added in the scripts. Please help!!! What am I doing wrong?
Hi Software Developer Guy (is that you real name?!? ),
This is actually the expected behavior. Let me try to explain what’s going on.
On a Skuid Model, pretty much anything that references a particular field on a particular record will be updated when any change is made to that field. So if you had a Table and a Field Editor which both reference the same Model and you edit a field with the Table, then you’ll see the change to that field immediately reflected in the Field Editor. This all happens on the client (your browser) without any need to go back and forth between the server (saving you a lot of time waiting for server responses).
As I’m sure you know, some fields in Salesforce are formula fields. Their values may be calculated from one or several other fields. That’s the case with your Name field - it’s calculated by concatenating the First Name and Last Name fields together. But that is occurring on the server, not in your browser. The only way to refresh that value is to send the value of your updated First Name to the server and then get the updated Name value back.
That’s exactly what’s happening when you click “Save”: Skuid is sending First Name to the server. The server then recalculates the value of Name and sends the updated Name field back to Skuid. Skuid detects that the Name field has changed since the last query and automatically updates any components which reference that field.
The good news is that there’s a fairly easy work-around. Rather than using FullName, use a Template Field with the following template:
Both FirstName and LastName will be automatically registered with the Model, allowing Skuid to update the template in real-time without the need to round-trip to the server:
Ah… sorry I didn’t notice your custom field renderer before. Basically, the issue is that your field renderer isn’t registered with the Model, so Skuid doesn’t know that the UI field needs to be re-rendered when the Model field is changed.
Fortunately that’s not too hard to fix! All you need to do is register the UI field via the .registerField( UIField, ModelFieldId ) function. For example:
var $ = skuid.$, field = arguments, value = arguments; field.model.registerField( field, "FirstName" ); field.model.registerField( field, "LastName" ); var firstName = field.model.getFieldValue( field.row, 'FirstName' ), lastName = field.model.getFieldValue( field.row, 'LastName' ); skuid.ui.fieldRenderers.STRING.read( field, firstName + ' ' + lastName );
The image below gives you a sense of the difference between using the standard Name renderer, using a Template Field with FirstName and LastName, and using the custom renderer which has been registered with the FirstName and LastName fields (the example code above):
If you can use the Template Field, I’d recommend it. It comes with some awesome extra features, like the ability to edit the individual fields in a popup:
Hi, Thank you so much. That is what I was missing!!! I know it works, but there is something I don’t understand. I thought that when you dropped a field onto an editor, that field was automatically registered with the model. I guess that is not the case. Is there some documentation that you can point me to understand more of the squid sequence of events? Thank you.
Yes, the field is registered automatically, but only with one Model field - the “initial” field, if you will.
For example, if you have a custom renderer defined for the Name field, then the UI field will be registered with the Name Model field, but not the First Name or Last Name fields. So, a change to the First Name field will not be reflected in the Name field until you send the Model to the server and get a response back.
By registering the Name UI field with the FirstName and LastName Model fields, the UI field will be re-rendered when there’s a change to the any of the three fields: Name, FirstName or LastName.
Thank you that makes sense. That was the piece that I could not figure out.