Can JQuery mobile show single active row hit by navigation slider - jquery-mobile

Can jquery mobile support such feature:
let's say there is a grid like 2 rows x 2 columns, it is shown as:
<table>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
<tr>
<td>ID1</td>
<td>Name1</td>
</tr>
<tr>
<td>ID2</td>
<td>Name2</td>
</tr>
</table>
ID, NAME
ID1, NAME#1
ID2, NAME2
, now I expect the grid is shown single row every time and there is a navigation slider to locate which row will be shown, i.e. let's move navigation slider to row 2, then row #2 will be shown in same effects as below codes (all columns are shown in rows):
<table>
<tr>
<td>ID :</td>
<td>ID1</td>
</tr>
<tr>
<td>Name :</td>
<td>Name#1</td>
</tr>
</table>
now for single row, it looks like:
ID: ID1
NAME: NAME1
, with a mobile device when user want to edit a row of a grid, the space is too small, I want to change to show selected row only and change layout of a record from landscape to portrait. After user finished editing, we can click another button to restore layout to HTML table style (multiple rows)
Have jQuery mobile provides such feature?

jQuery Mobile does not provide this functionality out-of-the-box. You would have to code it yourself. You might consider another option which is to add an edit button to each row of the table. Then when the user clicks the edit button, launch a jQM popup with the edit controls.
For each row in the table, add a cell with a button:
<tr>
<td class="editBtn">No text
</td>
<td>ID1</td>
<td>Name1</td>
</tr>
Add your edit form to the page same level as (header, footer, content):
<div data-role="popup" id="popupEdit" data-theme="a" class="ui-corner-all" data-dismissible="false">
<div class="ui-content">
<p>You are editing the row with ID: <strong id="editRow"></strong>
</p>
<hr />
<label for="txtID">ID:</label>
<input type="text" name="txtID" id="txtID" value="" />
<label for="txtName">Name:</label>
<input type="text" name="txtName" id="txtName" value="" />
<fieldset class="ui-grid-a">
<div class="ui-block-a">
<input type="button" value="OK" data-theme="b" class="popupbutton" />
</div>
<div class="ui-block-b">
<input type="button" value="Cancel" data-theme="a" class="popupbutton" />
</div>
</fieldset>
</div>
</div>
Add a click handler for the row edit button:
$("#MyTable .editBtn a").on("click", function () {
//get row id
var rowid = $(this).jqmData("rowid");
$("#editRow").text(rowid);
var $rowCells = $(this).closest("tr").find("td");
var curID = $rowCells.eq(1).text();
var curName = $rowCells.eq(2).text();
$("#txtID").val(curID);
$("#txtName").val(curName);
$("#popupEdit").popup("open");
});
In my example, and getting a rowid from a data-attribute, and the current ID and Name from the other row cells. These values are transferred to the popup and then the popup is launched.
DEMO
NOTE: you need to add the code that actually save the values depending on your database/backend server/localstorage/etc.

Related

Adding a Add Row button which then adds a new row for Amazon MTurk Form

I have a table set up in Amazon mturk with a single row which the user can fill in with the relevant details. However, sometimes the user will need to fill in two or three more rows of data. I want them to be able to click an "add new row" button and then a new row appears at the bottom of the table which is identical to the row above for them to fill in.
I tried looking at another task to see how they got the add row button to work but I can't figure out how they did it https://worker.mturk.com/projects/3PP5EK5QU1Q6PKONUENX4D1ESGSUNM/tasks?ref=w_pl_prvw
When I include their code of <input data-action ... it gives me an error saying the name is not defined
<!-- You must include this JavaScript file -->
<script src="https://assets.crowd.aws/crowd-html-elements.js"></script
<!-- For the full list of available Crowd HTML Elements and their input/output documentation,
please refer to https://docs.aws.amazon.com/sagemaker/latest/dg/sms-ui-template-reference.html -->
<!-- You must include crowd-form so that your task submits answers to MTurk -->
<crowd-form answer-format="flatten-objects">
<div>
<strong>Instructions: </strong>
<span>XX</span>
<div>
<div>
<p>Link to the Website: URL </p>
<p>City: "${City}"</p>
</div>
<div>
<table>
<tr>
<th>Plan Name</th>
<th>Price</th>
<th>Internet Quota (GB)</th>
<th>Local Quota (GB)</th>
<th>Other Quota</th>
</tr>
<tr>
<td>
<form>
<crowd-input name="Plan" placeholder="e.g. InternetMAX 4.5GB" required></crowd-input>
</form>
</td>
<td>
<form>
<crowd-input name="Price (Rp)" placeholder="e.g. 42000" required></crowd-input>
</form>
</td>
<td>
<form>
<crowd-input name="Internet Quota GB" placeholder="e.g. 0.5" required></crowd-input>
</form>
</td>
<td>
<form>
<crowd-input name="Local Quota GB" placeholder="e.g. 2" required></crowd-input>
</form>
</td>
<td>
<form>
<crowd-input name="Other Quota GB" placeholder="e.g. 0.5" required></crowd-input>
</form>
</td>
<td>
<input data-action="more-items" type="button" value="Add Items">
</td>
</tr>
</table>
</div>
</div>
</div>
```
``

Pass one of many objects from view to controller

In an ASP.Net Core web app, I'm passing a List<Parameter> to a view via ViewBag.Parameters. The view also has a SelectParameterViewModel that consists of one property only, an int ParameterId. The objects are then displayed in a table like so (I skipped straight to tbody as the view works fine from a cosmetic perspective):
#model WebApp.Models.ReportViewModels.SelectParameterViewModel
[...]
<tbody>
#foreach (var item in ViewBag.Parameters)
{
<tr>
<td class="col-xs-1">
<form asp-controller="Report" asp-action="Launch">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input asp-for="#Model.ParameterId" type="hidden" value="#item.Id" />
<input type="submit" class="btn btn-primary btn-sm" value="Select" />
</form>
</td>
<td class="col-xs-8">#item.Description</td>
<td class="col-xs-3">
<a asp-action="Edit" asp-route-id="#item.Id">Edit</a> |
<a asp-action="Details" asp-route-id="#item.Id">Details</a> |
<a asp-action="Delete" asp-route-id="#item.Id">Delete</a>
</td>
</tr>
}
</tbody>
I would like the user to click on the button of the chosen table-row and submit either that row's Parameter (preferred) or the Parameter's Id, like I tried to do in this case. I would then do the same with the <a> tags on the third column. The point is that I don't want the user to simply type /Report/Launch/id and run the report, as each user would have its own sets of parameters and should not be allowed to use any of the others', and the ViewBag only contains the list of its Parameter. I can change the view model and/or the receiving controller's argument depending on the solution, both would work. I tried a few versions of the above html, but none would work, while the above returns ParameterId with value 0.
I couldn't find a similar scenario in other SO questions. There were some solutions that involved JavaScript and, correct me if I'm wrong, but that would still show the ParameterId value in the webpage source. While that would be sort-of-ok in this specific case, I have other cases where I definitely would not want that to happen.
What would be an elegant solution to achieve this? Thank you!

Group of Radio Buttons with None selected in MVC

I'm new to MVC - I'm creating a simple survey application with a Survey Model and Controller and multiple Views in which users fill out their answers.
In my views I have a table of radio buttons, where each row is a group and the user has to select one radio button in each row. When the page loads, I want none of the radio buttons to be checked, forcing them to make a selection (throwing an error if they do not).
The problem is that the last radio button in each row is being selected somehow by default. I even specifically set one of the other buttons to checked to see what would happen, but when it loads it's still the last one that is checked. I have no idea why that is happening, how to change it, or even then what would be the best way to validate a selection is made in each group when the user tries to move on.
My Survey Model contains these STRING properties: mddbccu, mddtfuu, mddbccub, mddtfuub. There is nothing in my model except the properties.
This is an example of one of the rows of radio buttons in a view:
<tr>
<td>#Html.DisplayNameFor(Function(model) model.mddtfuu)</td>
<td>
<div><input name="mddtfuu" id="mddtfuu0" value="Never" checked="" type="radio"></div>
</td>
<td>
<div><input name="mddtfuu" id="mddtfuu1" value="Rarely" checked="" type="radio"></div>
</td>
<td>
<div><input name="mddtfuu" id="mddtfuu2" value="Sometimes" checked="" type="radio"></div>
</td>
<td>
<div><input name="mddtfuu" id="mddtfuu3" value="Usually" checked="" type="radio"></div>
</td>
<td>
<div><input name="mddtfuu" id="mddtfuu4" value="Always" checked="" type="radio"></div>
</td>
</tr>
Remove "checked" property from each radio button.
Thats it. Simple.......
i.e:
<input name="mddtfuu" id="mddtfuu0" value="Never" type="radio">

How to implement this validation in a Knockout-based form?

I started to work on an ASP.NET MVC4 solution with the SPA template (Single Page Application).
The starting template manage some todo lists with a kind of post-it design.
I slightly modified the template this way:
no more post-it design for dislaying elements
but a table to list all elements + delete + edit button on each element
at the end of the table: an add button
I have now the ability to edit one element in a form tag like this:
<form data-bind="with: currentTodoList, validate: true">
<h1>Edition</h1>
<table>
<tr>
<td>ID</td>
<td><b data-bind="text: todoListId"></b></td>
</tr>
<tr>
<td>User ID:</td>
<td><input class="required" data-bind="value: userId" /></td>
</tr>
<tr>
<td>Title:</td>
<td><input class="required" data-bind="value: title" /></td>
</tr>
<tr>
<td>Category:</td>
<td><input data-bind="value: category" /></td>
</tr>
</table>
<p>
<button data-bind="click: $parent.saveTodoList">Save</button>
<button data-bind="visible: todoListId, click: $parent.deleteTodoList">Delete</button>
<button data-bind="click: $parent.showGrid">Cancel</button>
</p>
</form>
As you can see above, I set the validate data-binding on the form tag and I have some input element with the class required.
When I test this implementation it doesn't work as expected. Example:
If I clear (empty) the userId field (which is required) I have a red validation message (picture 1). OK.
If I fill this userId field again, the red validation messaged disappeared. OK.
Then if I clear (empty) the title field (which is also required) I have the red validation message next to the userId field (picture 2). NOK.
The inverse is also true: userId <--> title. Any idea where is the problem?
Here is a link to download my test VS2012 solution to reproduce the problem.
Ok, so I played with your markup a little, with slight modification to the view model (not using a list, but editing a single entry).
Take a look at this jsfiddle - http://jsfiddle.net/Zxjrb/1/
I have added a span for validation message for ID and User ID, skipped the span for Title and Category.
<span data-bind='visible: todoListId.hasError, text: todoListId.validationMessage'> </span>
You can see the messages coming up, when Id or UserId field being empty, and that not happening for the title/category fields.

Twitter bootstrap modal inside of dropdown

I'm using the twitter boot-strap library within groovy grails and can currently get both modals and dropdowns to work, but not one inside the other. Here's the code I'm writing, it's so close, when I click on something inside of the dropdown, a psuedo modal shows up, it turns the screen black (transparency included in modals) but doesn't display the box with the info I supplied. Also I've noticed upon further inspection with firebug that only the first set of modals are made but the rest aren't, I'm confused why this is the case. Can anyone help?
Code:
<table>
<thead>
<tr>
<g:sortableColumn property="name" title="${message(code: 'course.name.label', default: 'Name')}" />
<g:sortableColumn property="description" title="${message(code: 'course.description.label', default: 'Description')}" />
</tr>
</thead>
<tbody>
<g:each in="${courseInstanceList}" status="i" var="courseInstance">
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
<td>
<ul class="nav nav-pills">
<li class="dropdown" id="menu${courseInstance.id}">
<a class="dropdown-toggle" data-toggle="dropdown" href="#menu${courseInstance.id}">
${courseInstance.name}
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<g:each in="${courseInstance.hasMany}" var="param">
<a data-toggle="modal", href="#myModal${courseInstance.id}${param.getProperties().key}", id="${courseInstance.id}${param.getProperties().key}">${param.getProperties().key}</a>
<div class="modal" id="myModal${courseInstance.id}${param.getProperties().key}">
<div class="modal-header">
<a class="close" data-dismiss="modal">x</a>
<h3>Students in ${courseInstance.name}</h3>
</div>
<div class="modal-body">
<g:javascript>
$('#myModal${courseInstance.id}${param.getProperties().key}').modal({
keyboard: true
})
$('#myModal${courseInstance.id}${param.getProperties().key}').modal('hide')
</g:javascript>
</div>
<div class="modal-footer">
Close
Save changes
</div>
</div>
</li>
</g:each>
</td>
<td>${fieldValue(bean: courseInstance, field: "description")}</td>
</tr>
</g:each>
</tbody>
</table>
There is a missing <li> element between the g:each and the a reference...but this should not be the point.
I'am using bootstrap with grails too, and I also use a modal within a navbar dropdown button, it works (but takes me several hours...).
I dont know for sure that it matters but i render the modal template outside of the dropdown. I also set the javascript to "modalize" the dialog below the modal div (not inside the modal-body).
Are you sure that everywhere the expression: myModal${courseInstance.id}${param.getProperties().key} is evaluated to same?
Also make sure that you dont import the modal.js manually (it is already imported in bootstrap.js). This caused some weird behaviour.
I'm using <div class="modal hide fade" id="..."> for the modal. This auto hides the div and adds some nice fade transitions (requires transitions.js).
Then the code reduces to: $('#...').modal({
keyboard: true,
show : false
})
Maybe some of these tips helps...
M.

Resources