Skip to main content

I am trying to put only one save/cancel button for the entire page.
however, I have models that are dynamically created using javascript. 
in the save/cancel button that i added to the page i can only select specific pre existing models.
and i cannot manually modify the xml in the page since i dont have the exact names of the models that will be created .is there a way to bind models to the save/cancel button dynamically when these models are created ?


My guess would be that instead of a save cancel button you need to to a run multiple actions button and have one of your actions be to run a java script snippet that saves the models that were dynamically created.


Kareem~

Have you checked out this tutorial? http://help.skuidify.com/m/11720/l/228794-dynamic-creation-of-models-and-components-with-javascript

Karen


thanks for the suggestion, we ended up trying to do that,  and it kind of works but then we need to render the button when there is any changes on these models, not sure how to do that now. 
I was just hoping there is a possible way to subscribe models to save buttons dynamically. this way we can take advantage of the default disable/enable of these buttons when changes occur, and any standard features that these buttons have 


that is a sticky one. This is a long shot but you might be able to create a dummy object in Salesforce that just stores one date/time field. You could create a model in Skuid based on that object so it would be recognized by conditional rendering. You could then have your Java snippets update the date field on that dummy model with the current date/time. That would create an unsaved change in that model which could be used to trigger the conditional rendering of your multiple actions button. Or it may be a complete waste of time. A short cut might be to just add a date/time field to an existing model recognized by conditional rendering and update that with field with your Java snippets.


Raymond is on the right track here.

Unfortunately, there isn’t a stock way to add models to buttons or be able to establish actions declaratively on.  But, using Raymond’s thought process, you can achieve the desired result.

1) Add a new model to your page (e.g. ChangeTracker).  Base it on any existing SObject in the system.  Mark it to “not load data” and “Create new row if none.”  Add a UI Only Field called “ModelsHaveChanges” as a Boolean with default value of “false”
2) Conditionally render the button in question based on Model & Field from #1 where it equals true
3) In an inline snippet, subscribe to the various model events (e.g. row.updated, row.created, models.saved, etc.).  In the snippet, check the modelId of the argument passed to compare against the models that you are “tracking” for changes.  When you get a change in one of those models, update the field on the model in #1 to “true”.  Also, check for when models were saved/cancelled so you can set the value to false as appropriate.

Hope this helps!


Does this make sense to everyone, as an implementation of Barry and Raymond’s ideas?


&#47;&#47; Global Save Buttons Javascript<br />(function (skuid){<br />&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;<br />&#47;&#47;Shortcuts &amp; Global Variables &#47;&#47;<br />&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;<br />var $ = skuid&#46;$,<br />$e = skuid&#46;events&#46;subscribe,<br />ChangeTracker;<br />&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;<br />&#47;&#47;Helper Functions &#47;&#47;<br />&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;<br />var checkForChanges = function(){<br />if (ChangeTracker) {<br />var changes = false;<br />$&#46;each(skuid&#46;model&#46;map(),function(){<br />if (this&#46;hasChanged &amp;&amp; this&#46;id !== 'ChangeTracker') {<br />changes = true;<br />}<br />});<br />ChangeTracker&#46;updateRow(ChangeTracker&#46;getFirstRow(), {'ModelChanges': changes});<br />}<br />};<br />&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;<br />&#47;&#47;Subscriptions &#47;&#47;<br />&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;<br />$e('models&#46;cancelled', checkForChanges);<br />$e('models&#46;saved', checkForChanges);<br />$e('row&#46;created', checkForChanges);<br />$e('row&#46;updated', checkForChanges);<br />$e('row&#46;deleted', checkForChanges);<br />$e('row&#46;undeleted', checkForChanges);<br />&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;<br />&#47;&#47;Pageload &#47;&#47;<br />&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;&#47;<br />$(document&#46;body)&#46;one('pageload',function(){<br />ChangeTracker = skuid&#46;$M('ChangeTracker');<br />});<br />})(skuid);

Hey Matt -  Generally speaking, this should do just fine 🙂