-1
I need your help,
I have two forms, Form 1 Form 2
in the Formulario 1
i have a date field, when filling out this date field I want it to copy to the Formulario 2
without me having to type, it is possible to do this using JAVASCRIPT
?
i can pull the data from the other form through this line of code
Service
var dia1Service = new Basics.Services.Services.Formulario.Dia1Service();
Form
var dia1 = dia1Service.getByCadastroId(id);
here below is my validation with JAVASCRIPT:
function validaDataDois(campo, valor) {
var variavelBasais = @(dadosBasais.isubrar);
var variavelDia1 = @(dia1.isubrd1);
var date = new Date(valor.split('/').reverse().join('/'));
var dataAlta = $('[name="dtirr"]').val();
var dataAltaValida = new Date(dataAlta.split('/').reverse().join('/'));
var dateDia1 = '@(dia1 != null && !string.IsNullOrEmpty(dia1.dtd1) ? Convert.ToDateTime(dia1.dtd1).ToString("dd/MM/yyyy") : string.Empty)'
var dateDia1Valid = new Date(dateDia1.split('/').reverse().join('/'));
var dataRandomizado = '@Convert.ToDateTime(ViewBag.datarandomizacao.ToString()).ToString("dd/MM/yyyy")';
var dataRando = new Date(dataRandomizado.split('/').reverse().join('/'));
if (!isValidDate(valor)) {
$('#dtirr-msg').show();
$('#dtirr-msg').text('Data inválida: ' + dataAlta);
$('[name="dtirr"]').val('');
}else if(variavelBasais == "1"){
if(dataAltaValida < dataRando){
$('#dtirr-msg').show();
$('#dtirr-msg').text('A data informada está menor que a data de randomização: ' + dataRandomizado);
$('[name="dtirr"]').val('');
}
}else if(variavelDia1 == "1"){
// A DATA TEM QUE APARECER NESSE CAMPO ABAIXO
$('[name="dtirr"]').val();
}
else {
$('#dtirr-msg').hide();
$('.valida_btn').prop('disabled', false).attr('disabled');
}
}
They will be on separate pages or on the same page?
– Lucas Caires
Separate pages, I saw here that to use the parameter @Model.xxx something of the kind to pull the data
– Leonardo Macedo
Yes it has to be in javascript, I edited the topic showing the line and code I use to pull the data from the other form
– Leonardo Macedo
I picked up the following explanation with a friend of mine only I didn’t quite understand "When you use "@Model.xxx" you’re going through Model Otherwise you have to change page...by passing the parameters in the url"
– Leonardo Macedo
If you are going to have page change, the ideal is to do it on the server. You can even do with javascript in the client, using localStorage, but in this case the most recommended is to use C#.
– Lucas Caires
@Leonardomacedo Could you explain better what you want? Would you like to pass a data from one form to the other? If so, how are the two fomulários? Want to do this on client or server? Forms are followed or to get to the second you must go through several screens?
– Randrade
When do you want me to go? No
submit
form 1? If it is, you can put it onViewBag
nay?– igventurelli
Next are two separate formulas from each other, when I enter form 2 it will load the date of form 1, without I need to type it again the 'Viewbag' is not pulling the dice
– Leonardo Macedo
I will edit the topic with my javascript validation
– Leonardo Macedo
@jbueno Because it is the simplest way. Using localStorage you may have problems with old browsers. It’s much easier to use a server side language to grab a form’s GET or POST than to scroll through a session (localStorage) to use only to replicate information.
– Lucas Caires
I put a comment in the validation field
– Leonardo Macedo