0
I have a function, it works perfectly, but I need to hide the fields, which do not need to appear to the client, but when hidden, the function does not receive the values, I am using this way:
<div class="col-md-4" id="fim">
<label id="lblFim" class="control-label">Data Fim</label>
<input id="txtVencimentoC" type="text" class="form-control" data-mask="00/00/0000" style="display:none" data-mask-reverser="false" />
<input id="txtTol" type="text" class="form-control" data-mask="00/00/0000" style="display:none" data-mask-reverser="false" />
<input id="txtDataTolerancia" type="text" class="form-control" style="display:none" data-mask="00/00/0000" data-mask-reverser="false" />
<input asp-for="PS.DataFim" id="txtDataFim" type="text" class="form-control" data-mask="00/00/0000" data-mask-reverser="false" />
</div>
I’m using the:
style="display:none"
Remembering that he is inside the end id=div, and sometimes I need to hide the whole div. I do it this way:
$("#fim").hide();
How can I hide the fields, and they continue to function ?
Edit: How I get the data in the function:
function GravarDados() {
var dataInicio = $("#txtDataInicio").val();
var dataFim = $("#txtDataFim").val();
var diaVencimento = $("#txtDiaVencimento").val();
var tolerancia = $("#txtTolerancia").val();
var valor = $("#txtValor").val();
var planoId = $("#cbplanos option:selected").val();
var tipoPlano = $("#txtTipoPlano").val();
var pessoaId = $("#id").val();
var proporcional = $("#lblProporcional").val();
var dataTolerancia = $("#txtDataTolerancia").val();
var vencimentoC = $("#txtVencimentoC").val();
var descricao = $("#cbplanos option:selected").text();
var pre = $('#cbpre').prop('checked');
var pos = $('#cbpos').prop('checked');
var pro = $('#cbproporcional').prop('checked');
var url = "/PessoasServicos/Gravar";
$.ajax({
url: url
, data: { DataInicio: dataInicio, DataFim: dataFim, DiaVencimento: diaVencimento, Tolerancia: tolerancia, Valor: valor, PlanoId: planoId, TipoPlano: tipoPlano, PessoaId: pessoaId, Descricao: descricao, Proporcional: proporcional, Pre: pre, Pos: pos, Pro: pro, DataTolerancia: dataTolerancia, VencimentoC: vencimentoC}
, type: "POST"
, datatype: "html"
, success: function (data) {
if (data.resultado > 0) {
location.reload();
}
}
});
}
If I make it visible, it receives the values, if I put the style="display:None" it does not receive the values.
Which plugin are you using there, girl? Wouldn’t it be the case that this lib is ignoring elements with
display: none
? You can add this information to the question?– Wallace Maxters
Your code works: http://jsfiddle.net/gdt5zmo0/ can show you the exact way you are using it?
– Sergio
When I take the data in a function to pass to the controller, it does not receive it.
– Mariana
@Sergio, could it not affect the fact that she is using ASP NET CORE? because your test is not taking into consideration the compilation that Net Core makes
– Wallace Maxters
I updated the question with the data, I use the same function in webforms, and it works with the style="display:None", but in ASPNET CORE, it doesn’t work.
– Mariana
this code is run " dry" on the page or within a function? what is the code string to get to that point? (cc @Wallacemaxters)
– Sergio
The function is called by clicking the button, it works, when the elements are visible, if I put the None display, it does not recognize.
– Mariana
@Sergio my concern is whether . NET CORE may be "removing" elements with
display: none
. It’s just a guess. If it changes the behavior of the tag based on an attribute, I thought the same might happen in the case of the display: None– Wallace Maxters
It worked here, instead of putting display:None, in the function even I hide, doing so: $("#txtDataTolerancia"). Hide(); $("#txtVencimentC"). Hide();
– Mariana