Greetings,
I want to apply a validation in form_customValidate, in which I execute a query to the database to know the current value of a field and compare it against the value selected by the user.i try this:
var $row = $(this).fields();
var $selected= $row['period'].val();
var $updated = "";
$.get(ew.getApiUrl(["currentVacationPeriod", $row['employeeCode'].val()]), function(res) {
if (res){
//alert(res);
//console.log(res);
$updated = res; //it must be the Currect Period Value
ew.alert(updated); //blank message
}
});
if ($selected !== $updated) {
ew.alert("The period selected must be de older", "", "danger");
$('#r_period').focus();
return this.addCustomError('period', 'The period selected must be de older'); // Return false if invalid
}
But the query shows nothing.Api_Action:
//Get the older period vacation
$app->get('/currentVacationPeriod/{employeeCode}', function ($request, $response, $args) {
$code = $args["employeeCode"] ?? null; // Get the input value
if ($code !== null) {
$response = $response->write(ExecuteScalar("SELECT MIN(period) as period FROM vvacations_period_days WHERE employeeID = '" . AdjustSql($code) . "'")); // Output field value as string
}
return $response; // Return Psr\Http\Message\ResponseInterface object
});
How can i do the query comparation??Thanks