So I tried this code in both shouldSelectRow notification as well as selectionShouldChange function
I've just entered data in a row and trying to validate it. If invalid want to ask user if want to continue editing or let the selected row change, at which point I will refresh to keep the last (i.e. "new") row of my table blank. Problem is if I say "Yes" it keeps asking me question again and again because the method gets called again and again. Why?
let isNew = //lastRowInTable
if isNew {
let check = validateRowAt(tableView.selectedRow)
if check.error {
let keep = shouldContinueEditing(check.message)
if !keep {
tableView.reloadData()
}
else {
tableView.editColumn(Column.description.hashValue, row: tableView.selectedRow, with: nil, select: true)
}
return keep ? false : true
}
}
Related
I have a function that is evaluating if an update is allowed for a user's profile. As you can see, the validProfileUpdate function calls the validFieldUpdate function for each field I have listed (in this case name and age). When I execute an update command for just one of the fields it will work, but when I uncomment the second one (in this case, for age) it will always fail. I only want these fields to be allowed to update based on if there's a change in data between what's being sent in and what already exists.
function validProfileUpdate() {
let validKeys = ['name', 'age'];
return request.resource.data.diff(resource.data).changedKeys().hasOnly(validKeys) &&
validFieldUpdate('name', validName()) &&
validFieldUpdate('age', validAge());
}
function validFieldUpdate(field, condition) {
return !(field in request.resource.data.keys()) ||
(request.resource.data[field] != resource.data[field] && condition);
}
What I'm having difficulty with is that I figured the line !(field in request.resource.data.keys()) in validFieldUpdate would catch any fields not included in the update that's sent and it would return true but for some reason that's not happening when I add the second field age.
So in summary, this works and only allows updates after it's sent for names that aren't Joe:
const profilePayload = {
name: 'Joe'
}
await userProfileRef.update({ ...profilePayload })
But this is blocked by the rules 100% of the time:
const profilePayload = {
name: 'Joe'
age: 25
}
await userProfileRef.update({ ...profilePayload })
You can use affectedKeys to compare the items rather than changedKeys as changedKeys only accounts for key values that are different from the original, a problem if the value stays the same.
let validKeys = ['name', 'age'];
if request.resource.data.diff(resource.data).affectedKeys().hasOnly(validKeys);
Affected:
which lists any keys that have been added to, removed from or modified from the Map calling diff() compared to the Map passed to diff()
Changed:
which lists any keys that appear in both the Map calling diff() and the Map passed to diff(), but whose values are not equal.
I'm creating a 'Kiosk' where users can sign-in and out.
I'm stuck on the sign-out component.
I'd like to have a table that only returns visitors that have not signed out after the end-user searches.
My search box has the following properties:
Value:
#datasource.query.filters.fullname._startsWith
On value change:
if (widget.value === null || (widget.value).length === 0){
widget.datasource.unload();
} else {
widget.datasource.load();
}
I'm new to this & JS as a whole. How can I filter the search to only contain users that have not signed out?
As suggested in the comments you need to add widget.datasource.query.filters.signedout._equals = false; line before you load your data source. However you should make one more change while unloading.
Here's the full code.
if (widget.value === null || (widget.value).length === 0){
widget.datasource.unload();
widget.datasource.load();
} else {
widget.datasource.unload();
widget.datasource.query.filters.signedout._equals = false;
widget.datasource.load();
}
Here unload() will unload previous data and load() will reload it. Now while reloading you can pass multiple filters so it reloads only filtered records.
How do I determine, if the Observable is "empty"?
Better, that it has never received anything.
My code looks like this:
spots: Observable<Spot[]>;
And I've tried several things I found on Google like:
spots.isEmpty();
spots.length;
spots.length();
spots().length;
spots.first();
But none of them works like I want..
I need this functionality, to fill a list in Ionic2 with No items found until the first item is loaded.
This is how I solve it in my code:
if ( arrayOfItems && arrayOfItems.length > 0 ) {
// display the list
return arrayOfItems.map((item) => { return item; })
} else {
// show a message that nothing was found
return "Nothing to see here...";
}
This will check that the variable has some sort of positive value (ie. it is not null, false or undefined) and that the array has at least one value. If that is not the case then display a message that nothing was found.
I solved it like this:
I have an variable let isEmpty=true; and set it to false when I receive the first Object in the Observable:
spots.subscribe(() => {
this.empty = false;
...
});
Given this code:
var Container = CRM.GetBlock("Container");
var CustomCommunicationDetailBox = CRM.GetBlock("CustomCommunicationDetailBox");
Container.AddBlock(CustomCommunicationDetailBox);
if(!Defined(Request.Form)){
CRM.Mode=Edit;
}else{
CRM.Mode=Save;
}
CRM.AddContent(Container.Execute());
var sHTML=CRM.GetPageNoFrameset();
Response.Write(sHTML);
Im calling this .asp page with this parameters but does not seems to work
popupscreeens.asp?SID=33185868154102&Key0=1&Key1=68&Key2=82&J=syncromurano%2Ftabs%2FCompany%2FCalendarioCitas%2Fcalendariocitas.asp&T=Company&Capt=Calendario%2Bcitas&CLk=T&PopupWin=Y&Key6=1443Act=512
Note the Key6=Comm_Id and Act=512??? which i believe it is when editing?
How can i achieve to fill the screen's field with entity dada?
In this case it is a communication entity
In order to populate a custom screen with data, you need to pass the data to the screen.
First, you need to get the Id value. In this case, we're getting it from the URL:
var CommId = Request.QueryString("Key6") + '';
We're going to put a few other checks in though. These are mainly to handle scenarios that have come up in different versions or from different user actions.
// check we have a value and get the Id from context if we don't
if(CommId == 'undefined'){
CommId = CRM.GetContextInfo("Communication","comm_communicationid");
}
// if CommId is still undefined, set it to zero to check later
// otherwise, make sure the URL only contains one CommId
if(CommId == 'undefined'){
CommId = 0;
} else if(CommId.indexOf(",") > -1){
CommId = CommId.substr(0,CommId.indexOf(","));
}
Certain user actions can make the URL hold multiple Ids in the same attribute. In these cases, those Ids are separated by commas. So, if the Id is not defined, we check if there is a comma in it. If there is, we take the 1st Id.
After we have the Id, we need to load the record. At this point, you should have already checked you have a valid id (E.g. not zero) and put some error handling in. In some pages you may want to display an error, in others you may want to create a new, blank record. This gets the record:
var CommRecord = CRM.FindRecord("communication","comm_communicationid = " + CommId);
After that, you need to apply the record to the screen. Using your example above:
CustomCommunicationDetailBox.ArgObj = CommRecord;
Adding all that to your script, you get:
var CommId = Request.QueryString("Key6") + '';
// check we have a value and get the Id from context if we don't
if(CommId == 'undefined'){
CommId = CRM.GetContextInfo("Communication","comm_communicationid");
}
// if CommId is still undefined, set it to zero to check later
// otherwise, make sure the URL only contains one CommId
if(CommId == 'undefined'){
CommId = 0;
} else if(CommId.indexOf(",") > -1){
CommId = CommId.substr(0,CommId.indexOf(","));
}
// add some error checking here
// get the communication record
var CommRecord = CRM.FindRecord("communication","comm_communicationid = " + CommId);
// get the container and the detail box
var Container = CRM.GetBlock("Container");
var CustomCommunicationDetailBox = CRM.GetBlock("CustomCommunicationDetailBox");
// apply the communication record to the detail box
CustomCommunicationDetailBox.ArgObj = CommRecord;
// add the box to the container
Container.AddBlock(CustomCommunicationDetailBox);
// set the moder
if(!Defined(Request.Form)){
CRM.Mode=Edit;
} else {
CRM.Mode=Save;
}
// output
CRM.AddContent(Container.Execute());
var sHTML=CRM.GetPageNoFrameset();
Response.Write(sHTML);
However, we would advise putting in more error/exception handling. If the user is saving the record, you will also need to add a redirect in after the page is written.
Six Ticks Support
How can i know specific value on a form using request.form?
I am trying it long but no success.
i want to check something like this
if (request.form.contains("text_check")) //But it doesn't work
{
go in;
}
else{
here we go;
}
i want to know specific value from AllKeys, and total count of all keys too.
To check if a key exists in the form data, you can simply compare the value to null:
if (Request.Form["text_check"] != null) {
If the key exists, you always get a string value back, even if the value is empty.
If you want to check if there is a non-empty value, you can use the String.IsNullOrEmpty method:
if (!String.IsNullOrEmpty(Request.Form["text_check"])) {
If you want to check if a certain key exists in the Request.Form collection you can do so like this:
if(Request.Form.AllKeys.Any(k => k == "text_check")) { ... }
and to then get it's value:
if(Request.Form.AllKeys.Any(k => k == "text_check"))
{
var textCheckValue = Request.Form["text_check"];
}
To get the total number of keys then:
var count = Request.Form.AllKeys.Count();
If you are using server side controls, you can use Request.Form.Contains(text_check.UniqueId) to make sure form is having that value during postback.