Manually setting the Lat/Long for a distance condition

  • 1
  • Problem
  • Updated 2 years ago
  • Solved
Currently on distance conditions, you have three options for the comparison location source. Fields from another model, running user's location, and page parameters. I want to be able to filter a list of contacts with the source location being manually selected. I am currently using a dummy model and have tried a combination of Ui Only fields and actual reference fields.

The problem is when using "Fields from another model", to get the condition to grab the latest change, you have to save that model and update both it and the model being filtered. This is problematic using a dummy model as I do not want to save the changes to it, and a UI only field would be reset doing this. 

I am setting the value for the distance value from my snippet. Is there anyway I'm missing to manually set the Lat/Long for that condition? I feel that would solve my problem.
Photo of Craig Rosenbaum

Craig Rosenbaum

  • 4,776 Points 4k badge 2x thumb

Posted 2 years ago

  • 1
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
Not exactly the answer you are looking for, but it is probably a quick fix for your issue.
I create a custom object called "Settings". I use it to collect any user preferences for Skuid Pages. You can add a model based on the settings object to any Skuid page and then save values to it as needed. The nice thing is that these changes persist after page refresh, so I use it for user specific filter preferences, background image choices, rendering of certain components like "one-time messages" on page load... very handy tool and it seems like it would fix your problem.
Photo of Craig Rosenbaum

Craig Rosenbaum

  • 4,776 Points 4k badge 2x thumb
I have a similar object called UserSettings that I use. However, I was hoping to avoid adding a field for this.
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Craig, I think that if the Condition's Location Source is set to Page parameters, then if you've got the Condition object in JavaScript you can populate the latitudeValue and longitudeValue properties and when you re-query, those values will be used as the comparison location, e.g.


var condition = myModel.getConditionByName("some_name");
condition.latitudeValue = 35.049309;
condition.longitudeValue = -85.3119634;
Photo of Craig Rosenbaum

Craig Rosenbaum

  • 4,776 Points 4k badge 2x thumb
Thank you Zach! This worked very well. I had not tried URL Params or to manually set the values of the condition (although I was checking them in the console). I seem to remember seeing somewhere that condition properties should be treated as read-only and not modified in JS. 
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
I would say, yes, Condition properties should be treated as read-only, but in this case there's no API for modifying the Lat/Long values manually, and these properties are not likely to change, so I'd say it's safe.
Photo of Craig Rosenbaum

Craig Rosenbaum

  • 4,776 Points 4k badge 2x thumb
Good to know. Thanks again for the help!