Passing data to another page

Asked

Viewed 1,524 times

-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?

  • Separate pages, I saw here that to use the parameter @Model.xxx something of the kind to pull the data

  • 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

  • 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"

  • 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#.

  • @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?

  • When do you want me to go? No submit form 1? If it is, you can put it on ViewBag nay?

  • 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

  • I will edit the topic with my javascript validation

  • @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.

  • I put a comment in the validation field

Show 6 more comments

1 answer

1


An alternative using Javascript only is to save the value in localStorage/sessionStorage and when you open the other page search for this value.

In the first form - assuming the transition will occur after a click on a button - save value in the localStorage.

$('button').on('click', function() {
    localStorage.setItem('algumaDataEspecial', valorDaDataEspecial);
});

In the second form you look for this value on localStorage and, if it exists, puts the value in the input

$(document).ready(function(){
    if(localStorage.getItem('algumaDataEspecial')){            
        var data = localStorage.getItem('algumaDataEspecial');
        //Colocar o valor no input, ou seja lá o que quer fazer
        localStorage.removeItem('algumaDataEspecial');
    }
});
  • did not work, you saw the script I posted in the post ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.