When executing function javascript screen items some

Asked

Viewed 55 times

1

Hello, when I run a javascript function, my screen items disappear, does anyone know why this might be happening?

My normal screen:

inserir a descrição da imagem aqui

My code of function: The items disappear in the validation function that is executed when opening the page

<script type="text/javascript">
        var vd = "";
        window.onload = function validacao() {
            vd = "@obterDado2()";
            if (vd == "True") {
                alertify.alert("Aviso", "Esse Tipo de Peça já existe, tente cadastrar um diferente", function () {
                    alertify.message('OK');
                });
                vd = @alterar();
            }
        }

        function ei() {
            $("#checked2").dxCheckBox({
                value: false
            });
        }

        function e() {
            $("#checked").dxCheckBox({
                value: false
            });
        }
    </script>

How does it look:

inserir a descrição da imagem aqui

It’s just weird that the same function works on another screen

Screen code:

@using SoftluxWebCore.ViewModels.Tabelas.Produtos
@using SoftluxWebCore.Controllers.Tabelas.Produtos

<!-- Link to CSS -->
<link href="~/css/Geral/create.css" rel="stylesheet" />

@using (Html.BeginForm())
{

    using (Html.DevExtreme().ValidationGroup())
    {
        @Html.AntiForgeryToken()
        <div class="divFormulario">
            @(Html.DevExtreme()
                .Form<AcabamentosViewModel>()
                .ID("formularioCadastro")
                .ShowValidationSummary(false)
                .Items(items =>
                {

                    items.AddGroup()
                    .Items(groupItems =>
                    {
                        groupItems.AddSimpleFor(m => m.CodAcabamento)
                        .Editor(e => e.TextBox().ElementAttr("class", "uppercase").MaxLength(10).Width("70px"));
                        groupItems.AddSimpleFor(m => m.DescAcabamento)
                        .Editor(e => e.TextBox().ElementAttr("class", "uppercase"));
                        groupItems.AddSimpleFor(m => m.DescAcabamento2).CssClass("cac")
                        .Editor(e => e.TextBox().ElementAttr("class", "uppercase"));
                    });
                    items.AddSimpleFor(m => m.Acab_situacao).CssClass("cat")
                        .Label(l => l.Visible(false))
                        .Editor(editor => editor.CheckBox().Text("Ativo"));

                    items.AddSimpleFor(m => m.acab_tipoE).CssClass("ce")
                        .Label(l => l.Visible(false))
                        .Editor(editor => editor.CheckBox().ID("checked2")
                        .OnOptionChanged("e").Text("Externo"));

                    items.AddSimpleFor(m => m.acab_tipoT).CssClass("ct")
                        .Label(l => l.Visible(false))
                        .Editor(editor => editor.CheckBox().ID("checked")
                        .OnOptionChanged("ei").Text("Externo e Interno"));

                    items.AddSimpleFor(m => m.acab_tipo2).CssClass("ctp2")
                        .Label(l => l.Visible(false))
                        .Editor(editor => editor.CheckBox().Text("Interno"));
                })
                .FormData(Model)
            )
        </div>
        <br />

        <button type="submit" class="btn btn-success btn-sucessoAC"><i class="far fa-check-circle"></i> Gravar</button>
        <button type="reset" class="btn btn-danger btn-cancelarAC" onclick="parent.fecharJanela('CadastroAcabamentos')">
            <i class="far fa-times-circle"></i> Cancelar
        </button>


        @functions{

            public string obterDado2()
            {
                string Validador = AcabamentosController.validar2;
                return Validador;
            }
            public string alterar()
            {
                AcabamentosController.validar2 = "";
                return AcabamentosController.validar2;
            }
        }

        <script type="text/javascript">

            function ei() {
                $("#checked2").dxCheckBox({
                    value: false
                });
            }

            function e() {
                $("#checked").dxCheckBox({
                    value: false
                });
            }
        </script>

    }
}

@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
}
  • Find the html in this box?

  • I will post, sorry

1 answer

0


I managed to solve

No need to call the function ObterDados2

Stayed like this:

    @functions{

        public string alterar()
        {
            AcabamentosController.validar2 = "";
            return AcabamentosController.validar2;
        }
    }

    <script type="text/javascript">
        var vd = "";

        window.onload = function() {
            vd = "@AcabamentosController.validar2";
            if (vd == "True") {

                alertify.alert("Aviso", "Esse Código já existe, tente cadastrar um diferente", function () {
                    alertify.message('OK');
                });
                vd = "@alterar()";
            }
        }
    </script>

Browser other questions tagged

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