Templates in field editor not updating on model query

  • 1
  • Question
  • Updated 3 years ago
  • Answered
I have a 3 separate field editors that have only template fields and is attached to a model. The template fields are populated by an inline JavaScript and I want to conditionally render each field editor.

When the field editors don't have a render condition on them all the data shows properly. Once I conditionally render the field editors the data does not appear. I checked the console and all the data loads on page load and model query so the data is there but I don't understand why it is not showing. 


Here is the code handling the page load and refresh

$(document.body).one('pageload', function() {        updateTemplateFields();
    });
    skuid.events.subscribe('models.loaded', function(updateResult) {
        if (updateResult.models.BillableDays)  {
           updateTemplateFields(); //Displays result on requery
       }
    });
})(skuid);
Photo of Tami Lust

Tami Lust

  • 5,280 Points 5k badge 2x thumb
  • confused

Posted 3 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
What does your conditional rendering statement look like?  If the data is there - I'd look there.  If the field editors show when the JS is run without conditional rendering,  then the rendering is your suspect. 

You could also do your coniditional rendering in your JS and only Render the component that makes sense for the use case at hand... 
Photo of Tami Lust

Tami Lust

  • 5,280 Points 5k badge 2x thumb
Rob,

Thanks for pointing me in the right direction. For whatever reason just the model query in the actions of my button was not enough to refresh the data, it needed  second refresh. So I added a action on the model that whenever it is refreshed (which happens through the button I created) the model will refresh again. That did the trick the data shows properly.

I am not sure if this is a bug or intended use but if you need more info just let me know.