Need help with my "condition" -- Browser.goto runs even if condition not met when using server connect data.
I have 2 conditions on my page..
If the condition is true then uses
<div id="condition_if_true" is="dmx-if" dmx-bind:condition="original_value.value==check_against_value.value">
Original Value is the same as checked value - perfect
<!-- {{browser1.goto('isthesame')}} -->
</div>
if the condition is NOT true it uses
<div id="condition_if_false" is="dmx-if" dmx-bind:condition="original_value.value!=check_against_value.value">
Original Value is <strong>not</strong> the same as checked value - perfect
<!-- {{browser1.goto('notthesame')}} -->
</div>
And this ALL works great.. and uses the browser.goto as it should when i use static values .... eg You can go and change the original_value and check_against_value to see how it works.. so that is great...
<body is="dmx-app" id="apptest">
<div is="dmx-browser" id="browser1"></div>
<dmx-query-manager id="query1"></dmx-query-manager>
<dmx-value id="original_value" dmx-bind:value="'yes'"></dmx-value>
<dmx-value id="check_against_value" dmx-bind:value="'yes'"></dmx-value>
Original Value: {{original_value.value}}<br>
Check Against Value: {{check_against_value.value}}<br>
<div id="condition_if_false" is="dmx-if" dmx-bind:condition="original_value.value!=check_against_value.value">
Original Value is <strong>not</strong> the same as checked value - perfect
<!-- {{browser1.goto('notthesame')}} -->
</div>
<div id="condition_if_true" is="dmx-if" dmx-bind:condition="original_value.value==check_against_value.value">
Original Value is the same as checked value - perfect
<!-- {{browser1.goto('isthesame')}} -->
</div>
</body>
BUT now my problem comes in... as soon as i fetch data from sc and want to use that data.. then it does not work the condition works ...but is disregarded the condition on the browser.goto... it just runs regardless of the condition set. Its as if the browser go to runs before the condition is met..
Is this a case of sc being to fast again or something can anyone please assist.
Im using php.
Here is my code if i use
<body is="dmx-app" id="apptest">
<div is="dmx-browser" id="browser1"></div>
<dmx-value id="userpermission_value" dmx-bind:value="userdetailsonsite.data.query1.user_permission"></dmx-value>
<dmx-value id="check_against_value" dmx-bind:value="'kioskconferencecheck'"></dmx-value>
{{userpermission_value.value}}<br>
{{check_against_value.value}}<br>
<div id="condition_if_false" is="dmx-if" dmx-bind:condition="userpermission_value.value!=check_against_value.value">
Original Value is <strong>not</strong> the same as checked value - perfect
<!-- {{browser1.goto('notthesame')}} -->
</div>
<div id="condition_if_true" is="dmx-if" dmx-bind:condition="userpermission_value.value==check_against_value.value">
Original Value is the same as checked value - perfect
<!-- {{browser1.goto('isthesame')}} -->
</div>
<dmx-serverconnect id="userdetailsonsite" url="dmxConnect/api/OnSite/user-details.php" ></dmx-serverconnect>
</body>
</html>
The output is this...
BUT when i uncomment the browser1.goto in both conditions.. the the first one run.. that is not supposed to... as the condition is not met...
<div id="condition_if_false" is="dmx-if" dmx-bind:condition="userpermission_value.value!=check_against_value.value">
Original Value is <strong>not</strong> the same as checked value - perfect
{{browser1.goto('notthesame')}}
</div>
<div id="condition_if_true" is="dmx-if" dmx-bind:condition="userpermission_value.value==check_against_value.value">
Original Value is the same as checked value - perfect
{{browser1.goto('isthesame')}}
</div>
I think you should be awarded for having the most creatively bizarre application of using browser1.goto being printed in the HTML template
The correct way is how Notum described, with the only difference I would've used an inline flow with a Condition instead of using a ternary operator. Your way I've never seen it done before
thanks ... i have a way of getting things to work as i use that alot if the conditions are true but thanks for the awards ill take that.. but let me give Notums idea a go
You will be surprised on how many times i have used this... then sure i have used it incorrectly but has always worked only i guess for if the conditions has been true eg ==
but effectively you can run it like this as well if you many conditions on the page
I have just tested this.. and working great.. using flows within the condition
Original Value: {{original_value.value}}<br>
Check Against Value: {{check_against_value.value}}<br>
<div id="condition_if_false" is="dmx-if" dmx-bind:condition="original_value.value!=check_against_value.value">
Original Value is <strong>not</strong> the same as checked value - perfect
<!-- {{browser1.goto('notthesame')}} -->
<script is="dmx-flow" id="flow1" type="text/dmx-flow" autorun="true">[
{
wait: {delay: 500}
},
{
run: {outputType: "text", action: "{{browser1.goto('notthesame')}}"}
}
]</script>
</div>
<div id="condition_if_true" is="dmx-if" dmx-bind:condition="original_value.value==check_against_value.value">
Original Value is the same as checked value - perfect
<!-- {{browser1.goto('isthesame')}} -->
<script is="dmx-flow" id="flow2" type="text/dmx-flow" autorun="true">[
{
wait: {delay: 500}
},
{
run: {outputType: "text", action: "{{browser1.goto('isthesame')}}"}
}
]</script>
</div>
The main issue why my previous "hack" did not work it because sc is to fast.. it seems for to browser.goto in the condition.. buy with the delay it works great..
Your solution using delay is prone to failure. You have a delay AFTER the initial condition check is performed, not before. It could as easily break after an App Connect update. You like to gamble, heh?
This is called a "race condition", you have no guarantee on the order of execution
lol.. i like to gamble i have to try everything i guess until it fails... thanks for the input as it always helps getting to a solution right or wrong... might not be conventional way or the correct way... but i did end of using dmx-on:ready on the body.. now i have also learn a new term "race condition"...
Just a question if one add a pre-loader... does the pre-loader make sure everything is loaded before it runs the conditional checks? So that one then avoid the "race condition" and then dont have to add a delay in a flow?
If your flow expects data from a server action on the page, why do you run it on page load and not on server action done event?
When the done event fires this means the server action data is available. Then you can run your flow and you can be sure the data is available so no need for wait steps (that are not 100% bulletproof solution).
The preloader is purely visual stuff, it shows the preloader animation while everything is loaded.
And also please don't use conditions like that:
that is a really bad practice. Use page flows for stuff like this.
Conditional regions are really supposed to be used for showing and hiding things on your page.
thanks for that explanation.. much appreciated.. its a case of "dont want to ask" and then creating bad habits.. and then want a fix
thanks for your simple solution once again... and pointing out the best way and bad practices....... i think...well guess i dont think... overthink.. gets me into trouble...