Multiple conflicting route parameter formats in Razor Pages - razor-pages

I'm making simple crud forms based on the tutorials for Razor Pages MVVM - https://learn.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/?view=aspnetcore-2.1
The issue is the elements on the Index page use different formats for the route parameter and I end up with URL's like /StockIndexMonths/2?StockIndexId=1
Where both /2 and StockIndexId=1 are the same parameter
The select list will use ?StockIndexId=1
The Create New link will use /1, when returning to the Index /1 is used
If I use the select list again I get both /1?StockIndexId=2
Can anyone tell me the preferred way to force the same parameter format to be used? I'm trying to keep Razor Pages doing it's 'magic'
Index.cshtml
#page "{StockIndexId?}"
#model Investments.Pages.StockIndexMonths.IndexModel
#{
ViewData["Title"] = "Index";
}
<h2>Index</h2>
<form>
<select asp-for="StockIndexId" asp-items="Model.StockIndexNameSelect" onchange="this.form.submit();"></select>
</form>
<a asp-page="Create" asp-route-StockIndexId="#Model.StockIndexId">Create New</a>
<table class="table">
...

Alter the form tag so that it uses the POST method:
<form method="post">
Currently, because the method is not specified, GET is used by default, which appends forms values to the URL as query string values. That's why you see what you are seeing.

Related

Signify for view to search for next task url

I am asking if there is a prefered method of making get_next_task_url() redirect to the next process url. get_next_task_url() looks for _continue in request.POST however the POST object is not able to be modified.
Currently i am adding a hidden field into my form:
<input id="continue" type="hidden" name="_continue" value="true">
Is there a variable that i can set within the views or flow classes to achieve the same thing?
Viewflow is the thin workflow layer on top of usual django views.
As for usual django views, to set redirect url can redefine get_success_url in your code
http://ccbv.co.uk/projects/Django/3.0/django.views.generic.edit/FormMixin/#get_success_url

Issue while saving the dynamic field values in the preferences

I have already posted one question on the same issue. But I'm not able to solve my issue and not able to move forward in my task.
I have created a editable portlet where in the configuration page I am showing he dynamic questions which are fetching form the database. So for the same reason I am iterating my array list and creating the input fields dynamically as follows,
Iterator<String> itr = al.iterator();
while(itr.hasNext())
{
String columnVal = itr.next();
columnVal = columnVal.trim().toLowerCase();
%>
<aui:input name="<%=columnVal%>" type="checkbox" />
<%
}
With the above code the fields are creating dynamically with proper labels and seems to be fine.
When I try to save these dynamic field values in the preference I changed my input statement syntax to the proper way by adding the prefix as "preferences--" and suffix as "--" as shown below,
<aui:input name="preferences--<%=columnVal%>--" type="checkbox" />
I don't know what syntax is wrong in the above statement. But I am not able to see the label names in UI. instead of showing the proper label names for all labels it is showing <%=columnVal%> on UI.
I am using default configuration action class in my liferay-portlet.xml as mentioned below,
<configuration-action-class>com.liferay.portal.kernel.portlet.DefaultConfigurationAction</configuration-action-class>
Can any one please correct my syntax and help me to save my dynamic field values in the preferences.
From reference link's comment section:
According to JSP 2.1 Specification multiple expressions and mixing of
expressions and string constants are not permitted.
So you have to use below code in your case:
<aui:input name='<%="preferences--"+columnVal+"--"%>' type="checkbox" />

Thymeleaf: Setting an arbitrary value to an arbitrary attribute

In my Thymeleaf template I need to set a custom attribute to a dynamically generated value. How would I do that?
I tried th:attr="name=value", but it seems to be pretty much strict about the 'value' part. For instance, I tried to generate the following attribute:
<div ng-init="myUrl='http://myhost.com/something'> ... </div>
where http://myhost.com/something is a dynamic part of the ng-init attrubute and is generated by Thymeleaf's URL expression, like #{...}
Any suggestions how to compose an expression that would produce the above piece of HTML?
Give this a try:
<div th:attr="ng-init='myUrl=\'' + #{http://myhost.com/something} + '\''">...</div>
It will output:
<div ng-init="myUrl='http://myhost.com/something'">...</div>

Passing arguments from node.js to knockout.js through ejs

I have a node.js that consumes mongodb data and outputs lists using knockout.js
When i invoke the view i pass a json structure using
res.render('list', { items:json });
In the list.ejs template page i've defined a hidden element:
<input type="hidden" id="hidden" value="<%= items %>">
and in .js file i read its value:
var json=$("#hidden").val();
var tkts=jQuery.parseJSON(json);
var vm=new AppViewModel(tkts);
Well...it runs but i think (hope) there must be a better way do it ... is there a way to avoid a hidden html var, for example?
Currently I can think of three ways to do this.
1.) Assign the data to a variable in your JavaScript code:
<script type="text/javascript">solution1 = {"name": "solution1"}</script>
solution1
2.) Add a data-attribute to an element of your liking:
<div id="solution2" data-value='{"name": "solution2"}'></div>
JSON.parse(document.getElementById('solution2').dataset.value)
3.) Use the script tag and choose a different content type than text/javascript or application/javascript
<script id="solution3" type="script" type="text/json">{"name": "solution3"}</script>
JSON.parse(document.getElementById('solution3').innerHTML)
Live demo
http://jsfiddle.net/bikeshedder/sbjud/
Personal note
It might sound boring, but the first option is probably the best choice. It is fast, requires as little code as possible and just works. I don't see a reason why you would want to have your data in a string first if you can have it as JavaScript data right away.
You could add an inline script if you are serving up a full page... Of course this would pollute the global namespace.
<script>
var tkts = <%= items %>;
</script>
If you are using AJAX to get this page... then break it into two AJAX requests... one of them gets the template, and the other one can get the list of items (as a JSON request). They could run in parallel so it might even be quicker.

Drupal 6: extracting input field of a search form out of div

The Drupal documentation about theming search forms says:
* $search['search_theme_form']: Text input area wrapped in a div.
My html page which i want to make a drupal theme uses a special search form so i don't want the form's elements to be wrapped into a div. How can i get the clean search form elements not wrapped into div?
Well the Drupal documentation pretty much says it all: http://drupal.org/node/45295
If you just want to remove the div container overwrite the template search-theme-form.tpl.php or whatever template is responsible for the input search field. You have the instruction on how to overwrite in the link above.
If you want more customization than you'll have to do step #2 from the Drupal tutorial.
So from this:
// #file /modules/search/search-theme-form.tpl.php
<div id="search" class="container-inline">
<?php print $search_form; ?>
</div>
To this:
// #file /sites/all/themes/your-active-theme/search-theme-form.tpl.php
<?php print $search_form; ?>
Don't forget to clear the Drupal's site cache.

Resources