Can i place an if condition on a submit button to update an old variable to a new variable ? It's imperative for me to declare it in my php file? And i'll appreaciate if you can tell me what approach will you use.
Assuming that i have an assigned var and the code will look like this:
<!-- {assign var='featured' value=$featured} -->
And i want to change or update, both the assigned variable and the value with new ones, what approach should i use and how can i store this in my php file in the case it can't be solely made from smarty template?
<!-- {if isset($newfeat) && $newfeat == 1}
{assign var='newfeatured' value=$newfeatured}{/if} --> I want this condition to be executed by pressing a submit button. I'm not much interested on the method and it can be .onclick do this condition above.
Related
I would like to shift focus on my page in response to keyboard input. With Svelte it seems that the simplest way is to use the autofocus attribute. However I cannot get conditional autofocus attributes to work.
Here's a simple repro of my problem: https://svelte.dev/repl/0861d097921d4a35957f016a8c35cfe6?version=3.44.3
Am I doing something wrong or is this not possible in Svelte 3?
Conditional autofocus was possible in a previous version of Svelte according to this question: Sveltejs render html attribute conditionally
And conditionality is possible for other attributes in Svelte 3 according to this question: How to have a conditional attribute in Svelte 3?
One solution could be to add a key block around the thing to make it re-run on every update of the focusIndex.
Example
{#key focusIndex}
{#each items as item, index}
<input autofocus="{index === focusIndex}" value={item} on:keydown={(ev) => test(ev)} />
{/each}
{/key}
Not the prettiest solution, but might unblock you.
Not strictly an answer to the exact question I asked, but the alternative that I've gone with is to use bind:this on the elements to create an array of the DOM elements and then in the keydown handler explicitly call .focus() on the DOM elements.
Example: https://svelte.dev/repl/83934cd7924741a8a4c5a620f79d5bb5?version=3.44.3
I have a spring application, with Oracle database behind. I have a user table in the database.
The users' active state in the database can have three values: -1, 0, 1.
I can access this value from thymeleaf this way: <span sec:authentication="principal.active"></span>
I would like to show a div only for the users that's active state is -1.
What's the correct <div th:if ...> syntax to check this?
Thank you!
You are looking for the following:
th:if="${#authentication.getPrincipal().active} == -1"
Watch out however, because depending on the version of thymeleaf-extras-springsecurity you are using, the access to the authenticated user differs (you might have to use #authentication.principal.active or something of the sort).
I'm am still pretty new to struts and am having trouble trying to compare two struts params in a struts if statement. I am trying find if the current year param is equal to the checkYear param
If they are equal I want to execute some code. If they are not equal then I would like to execute some other code..
Sample code:
<s:param name="currentYear">
<s:date name="%{new java.util.Date()}" format="yyyy" />
</s:param>
<s:param name="checkYear">
<s:date format="yyyy" name="#year"/>
</s:param>
<s:if test="${checkYear == legendYear}">
code executed
</s:if>
I don't really understand the purpose of the '$','%', or '{}' in the test part of the if statement if or how I need to apply it to have it check the params.
Thank you in advance!
Inside Struts2 tags, you use OGNL. Refer to the small language guide to see how it works.
In OGNL, %{} means you want to force the evaluation of an expression; it is needed somewhere, while it is superfluos somewhere else. In the <s:if/>, it is not needed, because test="" will evaluate its content by default.
${} does not exists in OGNL, it is JSP EL. Search on StackOverflow for some nice answer on that if you are curious.
{} alone in OGNL is List Projection... you probably don't need it now.
Here's the problem, I need to validate the form before submitting in the next way, before user can submit anything he should click "Save" button, if he tries to click "Submit" one receives message something like "You should save form before submit".
First I thought that I can add system field to the form like save-indicator, add constraint to like that
<xforms:bind id="isSaved-bind" nodeset="isSaved"
name="isSaved" type="xforms:string" constraint="number(.)=1" required="true()"/>
And add
<xforms:setvalue ref="xxforms:instance('fr-form-instance')/person/isSaved">1</xforms:setvalue>
to actions when "Save" button beeing clicked.
But, the problem is that I have to rewrite all existing forms to insert new code there.
Is there any posibility to make global variable like "isSaved" and check it for every form, before submit, and show error message if user didn't save form?
Or may be there another way that I can't see?
Will be appreciated for any answers.
Form Runner keeps track of whether the form is clean or dirty, and you can access that information in xxforms:instance('fr-persistence-instance')/data-status. The code handling the submit is in apps/fr/includes/persistence/persistence-model.xml. There you could change the listener for DOMActivate on fr-submit-button to read like:
<xforms:action ev:event="DOMActivate" ev:observer="fr-submit-button">
<xforms:action if="instance('fr-persistence-instance')/data-status = 'clean'">
<xforms:setvalue ref="instance('fr-persistence-instance')/submit-or-save-or-send">submit</xforms:setvalue>
<xforms:dispatch name="fr-save-action" target="fr-persistence-model">
<xxforms:context name="fr:check-data-valid" select="true()"/>
</xforms:dispatch>
</xforms:action>
<xforms:action if="instance('fr-persistence-instance')/data-status = 'dirty'">
<xforms:message>You must save form before submitting it.</xforms:message>
</xforms:action>
</xforms:action>
Note that persistence-model.xml is in orbeon-form-runner.jar. To change that file, extract it from there, and place it in the WEB-INF/resources/apps/fr/includes/persistence/persistence-model.xml. That version on WEB-INF/resources will take precedence over the one in the jar file. Also note that these type of changes that rely on the internals of Form Runner or Form Builder have a chance to break when upgrading to a new version of Orbeon Forms. So you might want to carefully keep track of them, so you can more easily reapply the changes when you upgrade.
I use a global flag indicator to check if the form is saved before closing the window or submit and it works pretty well.
This information is cleary explained in this wiki.
All the best!
The Grails documentation for the remoteFunction update attribute states:
update (optional) - Either a Map containing the elements to update for 'success' or 'failure' states, or a string with the element id to update, in which case failure events would be ignored
I'm a little confused why the indicate a Map and not a List here, is this wrong? I imagine I want my remote action to return a Map, where the keys match the name of the list elements specified in the update attribute??
Thanks
Use update, if you want to replace a part of the current page, which is identified by the (html)-id in the update tag. E.g.:
<div id="resultOfAJAX"></div>
<g:remoteFunction update="resultOfAJAX" [..] />
However this is not useful, if the AJAX call fails. That is why you can define which element is to be updated in the failure case:
<div id="resultOfAJAX"></div>
<div id="someErrorField"></div>
<g:remoteFunction update="[success: 'resultOfAJAX', failure: 'someErrorField']" [..] />
I am not sure, whether this clarifies your question regarding update, but maybe it helps ;)