Multiple datepicker with same classes in table - jquery-ui-datepicker

I need to make 2 or more table rows with datepicker inputs. They all have the same class names. When I select 'Start Date' the end date must NOT be greater than Start Date. If there is only one row the example works but for multiple rows with same classes it does not work. Please help.
HTML:
<table class="list">
<thead>
<tr>
<td>Title</td>
<td>Start Date</td>
<td>End Date</td>
<td></td>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" value="new 1" size="2"></td>
<td><input type="text" class="startdate" ></td>
<td><input type="text" class="enddate" ></td>
</tr>
<tr>
<td><input type="text" value="new 2" size="2"></td>
<td><input type="text" class="startdate"></td>
<td><input type="text" class="enddate"></td>
</tr>
</tbody>
JS:
$( ".startdate").datepicker({
dateFormat:'dd/mm/yy',
minDate: new Date(),
onSelect: function(dateStr) {
$('.enddate').datepicker('option', 'defaultDate', dateStr);
$('.enddate').datepicker('option', 'minDate', dateStr);
}
});
$( ".enddate" ).datepicker({
dateFormat:'dd/mm/yy',
minDate: new Date()
});
Here is JSFiddle example.

Since you have used class for endDate, it is affected all the elements with the same class.
Instead using the below approach you can make it to represent the endDate that particular row; therefore it won't affect the other endDate s in the table.
$(".startdate").datepicker({
dateFormat: 'dd/mm/yy',
minDate: new Date(),
onSelect: function (dateStr, ops) {
var endDate = $(this).parents('tr').find('.enddate');
$(endDate).datepicker('option', 'defaultDate', dateStr);
$(endDate).datepicker('option', 'minDate', dateStr);
}
});
JSFiddle
Here when you select the date from startDate, the below will get the endDate element of that particular tr.
var endDate = $(this).parents('tr').find('.enddate');
Thereby set the minDate for the above variable and your problem will be solved.

Related

Converting timestamps in postman within a template?

I'm using an html template within the Tests tab to output my json data, however, some of the data is in timestamp form. Is there a way to do the calculation to a more standard date/time format from within the var template ? I've read several ways to convert the timestamp, even one that I tried that I've commented out at the top but none work within the template variable. I've tried a few things but they cause the call to fail. Is it even possible to do within that template? Or how would you do it outside the template and then pull it back into the html? Because of the each loop I'm just not sure how to do this.
/*
let moment = require('moment'),
jsonData = pm.response.json()
date_created = jsonData.GetServerTimeResponse.date_created,
first_seen = jsonData.GetServerTimeResponse.first_seen,
last_seen = jsonData.GetServerTimeResponse.last_seen
*/
var template = `
<style type="text/css">
.tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #87ceeb;border-collapse: collapse;}
.tftable th {font-size:18px;background-color:#87ceeb;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;text-align:left;}
.tftable tr {background-color:#ffffff;}
.tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;}
.tftable tr:hover {background-color:#e0ffff;}
</style>
Dom: {{response.result.dom}}</br>
Rep: {{response.result.rep}}</br>
Reg: {{response.result.reg}}</br>
Date Created: {{response.result.date_created}}</br>
First Seen: {{response.result.first_seen}}</br>
Last Seen: {{response.result.last_seen}}</br>
<table class="tftable" border="1">
<tr>
<th>Name</th>
<th>Rep</th>
<th>First Seen</th>
<th>Last Seen</th>
</tr>
<tr>
</tr>
{{#each response.result.ns}}
<tr id=row_{{#key}} onClick="handleClick(this.id)">
<td id={{#key}}>{{host}}</td>
<td>{{rep}}</td>
<td>{{first_seen}}</td>
<td>{{last_seen}}</td>
</tr>
{{/each}}
{{#each response.result.send}}
<tr id=row_{{#key}} onClick="handleClick(this.id)">
<td id={{#key}}>{{id}}</td>
<td></td>
<td></td>
<td>{{last_seen}}</td>
</tr>
{{/each}}
</table>
`;
pm.visualizer.set(template, {
response: pm.response.json()
});

Loop over tbody in Django views

I am trying to loop over a tbody in my django views to get the data from the form but when i print the items in the tbody it only shows the last one
Here's the part I am trying to loop on
<tbody class="player-instances">
<tr>
<td><input type="text" name="form-0-pname" id="id_form-0-pname"></td>
<td><input type="number" name="form-0-hscore" id="id_form-0-hscore"></td>
<td><input type="number" name="form-0-age" id="id_form-0-age"></td>
</tr>
<tr>
<td><input type="text" name="form-0-pname" id="id_form-1-pname"></td>
<td><input type="number" name="form-0-hscore" id="id_form-1-hscore"></td>
<td><input type="number" name="form-0-age" id="id_form-1-age"></td>
</tr>
</tbody>
Views.py
if form.player_instances.cleaned_data is not None:
for item in form.player_instances.cleaned_data:
print("item", item)
print("form.cleaned_data", form.cleaned_data)
player = Player()
player.pname= item['pname']
player.hscore= item['hscore']
player.age= item['age']
player.save()
team.player.add(player)
team.save()
The output in terminal is the following:
item {'pname': 'tt22', 'hscore': 8, 'age': 89}
form.cleaned_data {'tname': 'tt1'}
Why is it overriding the first input fields despite having different id?
Try different name in name field like : form-1-pname and so on.
Thanks.

Ember list of checkbox on check one send rest

I have a list of checkboxes in my template:
<table>
<thead>
<tr>
<th></th>
<th>Sender</th>
<th>Title</th>
</tr>
</thead>
<tbody>
{{#each message in model.entities}}
<tr>
<td class="cell-star">
{{input type="checkbox" name=message.id tabindex=message.id class="starBox" checked=message.isStar }}
</td>
<td class="cell-broadcaster">
{{message.notification.autor.firstName}} {{message.notification.autor.lastName}}
</td>
<td class="cell-title">
{{#link-to 'notifications.details' message.notification.id}}{{message.notification.title}}{{/link-to}} {{#unless message.isRead}} (new) {{/unless}}
</td>
</tr>
{{/each}}
</tbody>
</table>
And now i want to send rest query every time when i change some of the checkbox state with id of changed checkbox.
What should i write in my controller?
i have tried something like that but i cannot get data of changed checkbox:
updateStarStatus: function() {
console.log('checkbox clicked');
//here should be something like that:
//$.getJSON(apiHost + "/api/forum/star/"+id);
}.observes('model.entities.#each.isStar'),
im not using emberData. My model looks like this:
model: function() {
return $.getJSON(apiHost + "/api/forum");
},
You could use the observesBefore method to track the changes and make a diff in the observes method, but I'd rather use the native on change event, to trigger an action and pass the object:
<div {{action "updateStarStatus" message on="change"}}>
{{input type="checkbox" checked=message.isStar}}
and in the controller
actions: {
updateStarStatus: function(message) {
alert(message.id)
}
}
http://emberjs.jsbin.com/zohaqodese/2/

Emberjs create a table with CollectionView

I wanted to generate a table with an array that I have in a controller but I don't really understand how does the collectionView is working.
Here are my array :
App.ApplicationView = Ember.View.extend({
accountProfile: null, //
actions: {
[...] //Action that initialize the accountProfile (object)
}
})
My array is accessible like this => view.accountProfile.dialInNumbers when I want to display on a template.
So now I have a table, but it must respect some standards like that :
<table class="table-history">
<tr>
<td class="col-left">+44734567890</td>
<td>
<div class="ph-img"></div>
</td>
<td>
<div class="tr-img"></div>
</td>
</tr>
</table>
Most likely what you have in the <tr> tag is what must be generated by the view. Most likely I will always have the first <td> that will change from the array in the view. The others <td> are meant to be the same every row.
My problem is that I don't really know how I can manage to create the collectionView and add the different class name with the others <td> in the same row..
I have seen some people doing this :
myView.appendTo('.table-history');
or even like this :
{#collection App.myView}}
<td>{{content}}</td>
{{/collection}}
But I'm kinda lost in this..
[EDIT]
I manage to make it works like this :
App.CallBackListView = Ember.CollectionView.extend({
tagName: 'tbody',
content: ['A','B','C']
})
{{#collection App.CallBackListView}}
<td class="col-left">{{content}}</td>
<td>
<div class="ph-img"></div>
</td>
<td>
<div class="tr-img"></div>
</td>
{{/collection}}
But I have one problem here, is that there is display in {{content}}. I don't really understand this..

View action link is not passing values to controller actions

I have the following view:
<h2>
Contract</h2>
#Using Html.BeginForm()
#Html.ValidationSummary(False)
#<fieldset>
<legend>Hire Contract</legend>
<div class="editor-label">
#Html.LabelFor(Function(model) model.ContractNo)
</div>
<div class="editor-field">
#Html.DisplayTextFor(Function(model) model.ContractNo)
</div>
<div class="editor-label">
#Html.LabelFor(Function(model) model.HireId)
</div>
<div class="editor-field">
#Html.DisplayTextFor(Function(model) model.HireId)
</div>
-- More fields here ---
<div>
<table>
<tr>
<th>
Line Id
</th>
<th>
Description
</th>
<th>
Return Quantity
</th>
<th>
</th>
</tr>
<p/>
#Html.ActionLink("Add Line", "AddContractLine")
<p/>
#For Each item In Model.HireContractLines
Dim currentItem = item
#<tr>
<td>
#Html.DisplayFor(Function(modelItem) currentItem.LineId)
</td>
<td>
#Html.DisplayFor(Function(modelItem) currentItem.Description)
</td>
-- Many other fields here ...
<td>
#Html.ActionLink("Edit", "EditContractLine", New With {.id = currentItem.LineId})
|
#Html.ActionLink("Delete", "DeleteContractLine", New With {.id = currentItem.LineId})
|
#Html.ActionLink("Return Line", "ReturnContractLine", New With {.id = currentItem.LineId})
</td>
</tr>
Next
</table>
</div>
<p>
<input type="submit" value="Full Return" />
</p>
</fieldset>
And the controller looks like:
Function EditContractLine(hireLineId? As Integer) As ActionResult
Dim contractLine = GetContractLine(CInt(hireLineId))
Return View(ContractLine)
End Function
However, when I click on Edit Line or Delete Line the value is not passed to controller action. It is always Null.
Can anyone please point me to the issue? Any comments will be appreciated.
I found what the problem was:
Parameter name should be same in the Action Link and the Controller Parameter.
eg .id should be .hireLineId to match the controller parameter name!!
#Html.ActionLink("Return Line", "ReturnContractLine", New With {.id = currentItem.LineId})