Closed VR-Architect closed 8 years ago
Could you reiterate the problem? What we had in mind when creating the nullable interface is avoiding inserting default values such as zero in doubles to the data source.
In the client side you still get the default value, but not in the data source which is relevant for operations such as update.
What do you think should be improved here?
The actually is a Xamarin.Forms.Entry control issue. If I set the bound object's field value to "null" for a double? type, the Entry control still shows a zero and not a null.
The real issue here is: How do we bind a double to a Xamarin.Forms.Entry control for "create" screen without forcing the user to erase the zero?
For LoopBack SDK, the SDK should allow us to set numeric values to null so they work with binding in Zamarin.Forms controls. Of course, the LoopBack web service should prevent a null from being entered. This my snippet code to determine to show the form as a "NEW" or "VIEW" form:
string _record;
MyLoopBackObject boundRecord;
public MyForm (string recordID)
{
_recordID = recordID;
}
protected override async void OnAppearing ()
{
base.OnAppearing ();
if (_recordID == 0) {
// No recordID was passed into the page so must be a new record request
boundRecord = new MyLoopBackObject();
boundRecord.id= "0";
// This is where we need to set the null if a new record
boundRecord.MyDouble = null;
} else {
// A recordID was passed into the form. This is a request to view an existing record
boundRecord = await wsHelper.GetMyLoopBackCallHere(_recordID);
}
BindingContext = boundRecord;
}
@VR-Architect, I am a little confused by this line:
NEVER MIND: The fix I recommend below does not remove the zero from the control. Please disregard this post. Thanks.
Is this issue still relevant or not?
@VR-Architect, I am closing the issue. Please re-open and mention me in a comment if it is still relevant.
NEVER MIND: The fix I recommend below does not remove the zero from the control. Please disregard this post. Thanks.
Please add the allow nullable to the private variables in the resulting cs file. In Xamarin.Forms I bind to my object's field (code3) using an Entry with a numeric keyboard. This results in a zero (0) being defaulted into the entry field when a new instance of the object is created in the UI (this is a new record scenario). The result is the user has to delete the zero and type in their number.
If a question mark was added in the public declaration like I show below, all works fine.
Here is my LoopBack snippet: