Empty load date whrn trying yo update - Yii2 - javascript

It happens that I have used the minDate option to deactivate the days before the current one to avoid selecting a date already in the past. This works perfectly for me in the create but in the update it does not show me the time, only the empty widget appears, although in the database it shows that the date was registered. I would like to know what error may be happening.
Rules
[['inicio_clase', 'fin_clase'], 'default', 'value' => function () {
return date(DATE_ISO8601);
}],
[['inicio_clase', 'fin_clase'], 'filter', 'filter' => 'strtotime', 'skipOnEmpty' => true],
[['inicio_clase', 'fin_clase','seccion_id', 'materia_id', 'estado'], 'integer'],
['inicio_clase','compare','compareAttribute'=>'fin_clase','operator'=>'<','message'=>'La fecha de inicio debe ser menor que la fecha de finalización.'],
['fin_clase','compare','compareAttribute'=>'inicio_clase','operator'=>'>','message'=>'La fecha de fin no debe ser menor o igual que la fecha de inicio.'],
Form
<?php echo $form->field($model, 'fin_clase'(
DateTimeWidget::class,
[
'phpDatetimeFormat' => 'yyyy/MM/dd HH:mm',
'clientOptions' => [
'minDate' => new \yii\web\JsExpression('new Date()'),
]
]
) ?>

You are probably trying to edit record with fin_clase set to the date before current date. The DateTimeWidget is set to not allow the date before the current day so it won't be able to show date in past even if that value is stored in model.
For example if today is 2021-10-12 and the record's fin_clase is set to 2021-10-11 it won't be filled during edit.
To avoid that you should set minDate to allow the actual value stored in model.
'minDate' => $model->isNewRecord
? new \yii\web\JsExpression('new Date()')
: new \yii\web\JsExpression("new Date({$model->fin_clase})"),
Or you might want to allow all dates in past when editing record.
'minDate' => $model->isNewRecord
? new \yii\web\JsExpression('new Date()')
: false,

Related

How can table_name be a property in my post query?

I want this query to be generic on the table_name meaning that there is in my JSON file a new property named "device" which indicates in which table the data will be inserted.
the problem is that in my SQL request I can't specify it. Here is what I tried:
INSERT INTO ${device} (adc_v, adc_i, acc_axe_x, acc_axe_y, acc_axe_z, temperature, spo2, pa_diastolique, pa_systolique, indice_confiance, received_on, bpm)' +
'values(${adc_v}, ${adc_i}, ${acc_axe_x}, ${acc_axe_y}, ${acc_axe_z}, ${temperature}, ${spo2}, ${pa_diastolique}, ${pa_systolique}, ${indice_confiance}, ${received_on}, ${bpm})'
here is my JSON on postman:
{
"device": "tag_7z8eq73",
"adc_v": 130,
"adc_i": {{RandomCourant}},
"acc_axe_x": {{RandomAccX}},
"acc_axe_y": {{RandomAccY}},
"acc_axe_z": {{RandomAccZ}},
"temperature": {{RandomTemp}},
"spo2": {{RandomSpo2}},
"pa_diastolique": {{RandomDias}},
"pa_systolique": {{RandomSys}},
"indice_confiance": {{RandomIndiceConf}},
"received_on": "{{$isoTimestamp}}",
"bpm": {{RandomBpm}}}
The table name is : tag_7z8eq73
here is the error that is returned to me:
error: erreur de syntaxe sur ou près de « 'tag_7z8eq73' »
Looks like I am close to the solution but there is a syntax problem, the quote ? is my way the right one?
const device = req.body.device;
console.log(device)
return db.none('INSERT INTO '+device+' (adc_v, adc_i, acc_axe_x, acc_axe_y, acc_axe_z, temperature, spo2, pa_diastolique, pa_systolique, indice_confiance, received_on, bpm)' +
'values(${adc_v}, ${adc_i}, ${acc_axe_x}, ${acc_axe_y}, ${acc_axe_z}, ${temperature}, ${spo2}, ${pa_diastolique}, ${pa_systolique}, ${indice_confiance}, ${received_on}, ${bpm})',
req.body)
try this

How to export an Array to PDF using jsPDF?

first time using jsPDF.
I'm trying to export some data via PDF, however when I try to export the array it gives me an error. I have ASSUMED you export arrays using doc.table because I can't get to find any documentation, there's a tag for it in stackoverflow for questions but didn't find anyone with the same question neither.
This is what I have so far
const generatePDF = () => {
var doc = new jsPDF('landscape', 'px', 'a4', 'false');
doc.addImage(AIBLogo, 'PNG', 250,10,100,100)
doc.setFont('Helvertica', "bold")
doc.text(60,150, "Informacion del Pedido");
doc.setFont('Helvertica', "Normal")
doc.text(60,170, "Estado del Pago: "+estadoDePago)
doc.text(60,190, "Estado de Disponibilidad: "+estadoDeDisponibilidad)
doc.text(60,210, "Total del Pedido: "+total)
doc.text(60,230, "Total Pagado: "+totalPagado)
doc.setFont('Helvertica', "bold")
doc.text(360,150, "Informacion del Estudiante");
doc.setFont('Helvertica', "Normal")
doc.text(360,170, "Nombre del Estudiante: "+nombre)
doc.text(360,190, "Escuela: "+escuela)
doc.text(360,210, "Estado del Pago: "+grado)
doc.text(360,240, "Direccion de Entrega: Retirar en institución")
doc.table(100,100, librosData)
doc.save(id+".pdf")
}
Excluding the table bit it prints out like this:
I would like to add the DataTable after all that info and make new pages if is out of bounds cause table can be up to 20 items.
UPDATE
I have try the following but is not working neither I got it from here: StackOverflow Answer
var col = ["Descripcion", "Tipo", "Editorial","Precio"]
row = []
for (let i = 0; i < librosData.length; i++){
var temp = [librosData[i].descripcion, librosData[i].tipo, librosData[i].editorial, librosData[i].precio];
row.push(temp)
}
doc.autoTable(col,row, {startY:380});
doc.save(id+".pdf")
I know all the data is coming correctly this is how the row is printing:
Any help or documentation is appreciate it.
Final Update
To fix the issue that says autotable is not a function just
Solution: StackOverflow
In the end to make the table I recommend this:
To do the table: How to export a table with jsPDF
To fix the compatibility: autoTable is not a function
To fix "deprecated autoTable initiation":
Initialize your autoTable the following way
import autoTable from 'jspdf-autotable'
autoTable(doc, {
head: [col],
body: row
})

Button not working discord.js discord-buttons

hello so i write this code
module.exports.run = async (Client, message, args, prefix) => {
if (!message.content.startsWith(prefix)) return;
disbut(Client);
let button1 = new disbut.MessageButton()
.setStyle("green") //default: blurple
.setLabel("créer un channel") //default: NO_LABEL_PROVIDED
.setID("create"); //note: if you use the style "url" you must provide url using .setURL('https://example.com')
let button2 = new disbut.MessageButton()
.setStyle("red") //default: blurple
.setLabel("fermer un channel") //default: NO_LABEL_PROVIDED
.setID("close"); //note: if you use the style "url" you must provide url using .setURL('https://example.com')
message.channel.send("Cliquer sur les boutons pour effectuer une action ", {buttons : [button1, button2] });
};
if i execute my command the texte is send in my channel but not the button
and i dont understand why and i dont have any error
thanks for your help :)
In Discord.js v13, the send method only takes a single parameter. Discord.js is only looking at "Cliquer sur les boutons..." and not the second object you are providing.
Instead, use a single MessageOptions object:
message.channel.send({
content: "Cliquer sur les boutons pour effectuer une action ",
buttons: [button1, button2]
});
For more information, see this section in the Discord.js guide.

How to get .on("change") to work with gldatepicker?

I have a date select box that when a date is selected, the date will be used in a calculation.
<? echo $this->Form->input( 'start_date', array( 'label' => __('Show only accounts made since:'), 'value' => '', 'readonly' => 'readonly' ) ); ?>
The Javascript I tried:
$('#start_date').glDatePicker({ cssName: 'darkneon'});
$("#start_date").on("change",function() {
var date = this.value;
console.log (date);
do_stuff(date);
});
The console shows nothing when I select a date. I am clearly missing something. Is on-change even the right way to handle this?
Try this:
$('#start_date').glDatePicker({
cssName: 'darkneon',
onClick: function(target, cell, date, data) {
console.log (date);
do_stuff(date);
}
);
From the docs (find with Ctrl+f):
Callback that will trigger when the user clicks a selectable date.
Example (check example #3)

jQuery Validation - skip_or_fill_minimum rule does not fire if it is used more than once

I have a form that is composed by four inputs, and they're grouped in pairs.
The rule for this form is very simple, if I fill out one of the inputs of the pair, I have to fill out the other too or I don't fill out any, so to achieve this behaviour I used skip_or_fill_minimun method.
The HTML:
<div id="msgErros"></div>
<form>
<label for="dataInicial">Data Inicial</label>
<input type="text" name="filtro.dataInicial" id="dataInicial" class="datas" />
<label for="dataFinal">Data Final</label>
<input type="text" name="filtro.dataFinal" id="dataFinal" class="datas" />
<br />
<label for="tempoInicial">Tempo Inicial</label>
<input type="text" name="filtro.tempoInicial" id="tempoInicial" class="tempos" />
<label for="tempoFinal">Tempo Final</label>
<input type="text" name="filtro.tempoFinal" id="tempoFinal" class="tempos" />
<br />
<button type="submit">Enviar</button>
</form>
The validation rules, messages and groups:
$("form").validate({
rules : {
"filtro.dataInicial": {
skip_or_fill_minimum: [2, ".datas"]
},
"filtro.dataFinal": {
skip_or_fill_minimum: [2, ".datas"]
},
"filtro.tempoInicial": {
skip_or_fill_minimum: [2, ".tempos"]
},
"filtro.tempoFinal": {
skip_or_fill_minimum: [2, ".tempos"]
}
},
messages: {
"filtro.dataInicial": {
skip_or_fill_minimum: "Por favor, preencha ambos os campos de data ou nenhum deles."
},
"filtro.dataFinal": {
skip_or_fill_minimum: "Por favor, preencha ambos os campos de data ou nenhum deles."
},
"filtro.tempoInicial": {
skip_or_fill_minimum: "Por favor, preencha ambos os campos de tempo ou nenhum deles."
},
"filtro.tempoFinal": {
skip_or_fill_minimum: "Por favor, preencha ambos os campos de tempo ou nenhum deles."
}
},
groups : {
grupoDatasAtendimentoSintetico : "filtro.dataInicial filtro.dataFinal",
grupoTemposAtendimentoSintetico : "filtro.tempoInicial filtro.tempoFinal"
},
errorContainer : "#msgErros ul",
errorLabelContainer : "#msgErros",
wrapper : "li"
});
The problem happening here is that if I fill out one of the first two inputs the rule isn't fired at all, the problem does not occur if I do it with the second pair. If I delete the second pair the rule executes just fine so I think this is a bug. Here's a fiddle.
I read about this method and require_from_group causing problems that simply prevents other methods from being executed but this issue is supposed to be corrected in the version 1.11.1 which is the one I'm using in my project and in the fiddle for both the plugin itself and the additional methods.
The problem happens only when the user fill out one of the fields in the first pair. Does anyone know if this is another bug? I haven't found nothing related to this in the GitHub issue tracker of this plugin.
UPDATE:
I just placed an issue in the plugin's issue tracker.
The problem you are reporting has been resolved in a recent commit.
I've updated your Fiddle. I removed the external dependencies, copied and pasted the code from http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js in the begining of the JavaScript section, followed by the code from http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.js - an at the end I kept your JavaScript untouched.
Then, I've picked up the most recent version of "skip_or_fill_minimum" code here: https://github.com/jzaefferer/jquery-validation/blob/master/src/additional/skip_or_fill_minimum.js
jQuery.validator.addMethod("skip_or_fill_minimum", function(value, element, options) {
var $fields = $(options[1], element.form),
$fieldsFirst = $fields.eq(0),
validator = $fieldsFirst.data("valid_skip") ? $fieldsFirst.data("valid_skip") : $.extend({}, this),
numberFilled = $fields.filter(function() {
return validator.elementValue(this);
}).length,
isValid = numberFilled === 0 || numberFilled >= options[0];
// Store the cloned validator for future validation
$fieldsFirst.data("valid_skip", validator);
// If element isn't being validated, run each skip_or_fill_minimum field's validation rules
if (!$(element).data("being_validated")) {
$fields.data("being_validated", true);
$fields.each(function() {
validator.element(this);
});
$fields.data("being_validated", false);
}
return isValid;
}, jQuery.validator.format("Please either skip these fields or fill at least {0} of them."));
And, finally, pasted this code substituting the prior version which was at the Fiddle.
With this, the problem vanished! From this we conclude that the bug really existed but it has been already fixed.
Update:
Version 1.11.1 is from March 22, 2013 (https://github.com/jzaefferer/jquery-validation/tree/1.11.1). The commit which fixes the bug is from August 27, 2013 (https://github.com/jzaefferer/jquery-validation/commit/e5207d63a831fdfa30ea6927906288ae60336c76)
There is nothing wrong with your code. It is a bug in jQuery Validate. The bug exists in version 1.11.1 - either you wait for a new release, ou you must apply the fix on your own.
To apply the fix , you need to substitute the buggy skip_or_fill_minimum code for the most recent one (pasted above). Use the non-minimized version of additional-methods.js for this. (You can minimize it later with "uglify.js" or other tool, if you want.)

Categories

Resources