Eduardo Fuerte
asked on
Could you point how to correctly positionate a jQuery code that must to be fired only in case of new records?
Hi Experts
Could you point how to correctly positionate a jQuery code that must to be fired only in case of new records?
Since the datetime column represents when the record is created it must not to be actualized when editions are done.
Coding this way when editing the Data is changing too (it must only bring the date creation value - no changes allowed)
Since the same modal is used for insertions and editions - a jQuery code already exists to diferentiate:
Since the edition button is part of "Datatables plugin" structure, it must to be defined just here to work out....
Thanks in advance.
Could you point how to correctly positionate a jQuery code that must to be fired only in case of new records?
Since the datetime column represents when the record is created it must not to be actualized when editions are done.
Coding this way when editing the Data is changing too (it must only bring the date creation value - no changes allowed)
<input value="" type='text'id='data' name='data' class="form-control gui-input br-light light" placeholder="" readonly=""/>
<script type="text/javascript">
jQuery(function() {
var d2 = function(n) { return n>9?n:"0"+n; };
setInterval(function() {
var d = new Date();
var dd = d2(d.getDate());
var mm = d2(1+d.getMonth());
var yyyy = d.getFullYear();
var hh = d2(d.getHours());
var mi = d2(d.getMinutes());
var ss = d2(d.getSeconds());
$("#edit #data").val( dd + "-" + mm + "-" + yyyy + " " + hh + ":" + mi + ":" + ss );
}, 200);
});
</script>
Since the same modal is used for insertions and editions - a jQuery code already exists to diferentiate:
function titulo_modal() {
if($("#idinterface_users").val() > 0) {
$(".titulo-mutavel").html("Editar ");
}
else if($("#idinterface_users").val() == "") {
$(".titulo-mutavel").html("Novo ");
}
else if($("#id").val() == "") {
$(".titulo-mutavel").html("Novo ");
// - The jQuery code must come here to be fired just when a new register is started (?)
// ?????
}
else {
$(".titulo-mutavel").html("Editar ");
}
}
Since the edition button is part of "Datatables plugin" structure, it must to be defined just here to work out....
Thanks in advance.
ASKER
@Ray
This case is much more a case of datetime presentation. If starting a new record the datetime of server (or even local machine) must be presented. If editing a record the datetime of the record creation must to be presented.
I tryed to use your code from precedent question too:
jQuery code adapted:
This case is much more a case of datetime presentation. If starting a new record the datetime of server (or even local machine) must be presented. If editing a record the datetime of the record creation must to be presented.
I tryed to use your code from precedent question too:
jQuery code adapted:
function titulo_modal() {
if($("#idinterface_users").val() > 0) {
$(".titulo-mutavel").html("Editar ");
}
else if($("#idinterface_users").val() == "") {
$(".titulo-mutavel").html("Novo ");
}
else if($("#id").val() == "") {
$(".titulo-mutavel").html("Novo ");
// --- Precedent question: loads when modal is presented - I guess
//$("#data").click(function(){
loadDateBox($("#data"));
//});
//-----------------------
}
else {
$(".titulo-mutavel").html("Editar ");
}
}
//--- Precedent question:
function loadDateBox(element){
$.get("temp_eduardo_server.php", function(response){
$(element).val(response);
});
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@Ray
What you post is correct but my issue here is to actualize the datetime textbox between insertions by using server side or browser side functionality - every insertion has its own datetime. A page reload for that purpose is not accepted here.
@Chris
Very logical. I'm searching where is the correct place.
What you post is correct but my issue here is to actualize the datetime textbox between insertions by using server side or browser side functionality - every insertion has its own datetime. A page reload for that purpose is not accepted here.
@Chris
Very logical. I'm searching where is the correct place.
ASKER
Really
Following your instructions:
This code trigger "New" (Novo) button:
And then in jQuery code
Since I'm using Codeigniter I'm going to put the "temp_eduardo_server.php" code in controller and call it using AJAX then...
So, it runs... changing datetime between insertions without reloads. Accordingly to:
Just one thing more... this re-configuration of date format apparently has no effects(?!)
What is missing?
Following your instructions:
This code trigger "New" (Novo) button:
<div class="col-xs-12 pln">
<button
class="btn btn-primary btn-gradient btn-alt btn-block item-active save_button"
id="create"
style="width:100%"
type="submit">Novo</button>
</div>
And then in jQuery code
$('#create').click(function () {
//console.log('Botao Novo');
loadDateBox($("#data"));
});
function loadDateBox(element){
$.get("temp_eduardo_server.php", function(response){
$(element).val(response);
});
}
Since I'm using Codeigniter I'm going to put the "temp_eduardo_server.php" code in controller and call it using AJAX then...
So, it runs... changing datetime between insertions without reloads. Accordingly to:
Just one thing more... this re-configuration of date format apparently has no effects(?!)
<?php
error_reporting(E_ALL);
//echo date('c');
echo date("d-m-Y H:i:s");
What is missing?
re-configuration of date format apparently has no effects...Maybe you are testing the wrong script? When we are working with tiny code fragments it is hard to know what else might be in play. Suggest you spin each of the issues out into one SSCCE for each of the parts that you want to isolate and test. Greater isolation will give you better individual test cases.
http://sscce.org/
ASKER
Thank you for the very good orientations!
ASKER
Application is perfectly running. Thank you one more time!
https://dev.mysql.com/doc/refman/5.5/en/datetime.html
https://dev.mysql.com/doc/refman/5.5/en/timestamp-initialization.html