Need Model / Render Conditions to be accurate to time (hours/minutes) not just dates

  • 1
  • Problem
  • Updated 4 years ago
Model and Render Conditions support TODAY for Date and DateTime comparisons (though TODAY doesn't work in a Render Condition, but I see that bug was reported a few months ago).  I have a need to be able to compare against NOW (including the current time) for DateTime objects and have been trying to implement that via a snippet.

I've got it working on a model condition where I set the condition to use a specific date/time in the designer, and then change the comparison value in the models condition array when the page loads.  For example,

model.conditions[0].inactive = false;
model.conditions[0].value = (new Date()).toISOString();
model.updateData()

I've not had the same luck with conditional renders.   I've found the component (such as $('#myComponent').data('component'), or skuid.component.getById('myComponent')), and in there I can find element.conditions ... but the conditions array is empty even though I have a render condition on my component.  So likely I'm looking in the wrong place?  

How can I find the render condition in a snippet to change the comparison value?

And it would be great to see NOW as an available option in the list of conditions!

Thanks,

- Chris
Photo of Chris

Chris

  • 1,632 Points 1k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Chris

Chris

  • 1,632 Points 1k badge 2x thumb
I've been able to learn a bit more, but still not there...

I see that the component.xmlDefinition array appears to contain the specification for the entire component in XML, and within that there is the "renderConditions" section contains the render criteria.  I've been able to successfully locate the correct "value" attribute and change it to represent now().  That of course doesn't do anything, since I've not informed the component that the XML has changed.

I also see a createConditionsFromXml method, which I'm guessing can convert that XML into some memory state for those conditions.  But I don't yet see how to use it, nor know if it will then cause the condition to render correctly.

Better would be to find the in-memory representation of the conditions so I could simply change the date/time value of the condition to now (date.toISOString()) until / if you can create a new "NOW" condition, similar to how I am doing it for model (see above).

Hopefully this helps guide you a bit in helping me find a workaround!

Thanks as always...

- Chris
Photo of Menachem Shanowitz

Menachem Shanowitz

  • 1,074 Points 1k badge 2x thumb
I don't think there is any in-memory representation of the render conditions other than the XML.
(Edited)
Photo of Emily Davis

Emily Davis, Employee

  • 3,502 Points 3k badge 2x thumb
Chris,
There are actually two methods for skuid.component.Component: unrender() and render() that will probably work for you. You can call these and the component will dynamically be hidden or shown. I guess the unrender() method is not in our documentation. Or, if you have already created your render conditions and simply need a way to update the component in the ui, you can call conditionallyRender(), and it should render or unrender the component based on the condition's values. Hope this gets you a little farther!
Emily