Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
AngularJs form validation not working with ng-show

I am struggling with ng-show and $invalid logic, my requirement is very simple I need to make a form that will show input fields based on conditions.

I need to add one datetime picker of moment.js.

Issue starts when I understand that my datetime picker is not working with ng-if because ng-if removes the element from the DOM and my datetime picker can't work with this, I used ng-show instead and it worked. But the issue is my form is divided into multiple different forms based on conditions I am showing different inputs and datetime picker is not in all the conditions.

This thing causing my submit button to kept disabled on those conditions when I am not showing datetime picker.

I tried finding a lot thought of using ng-switch as well but I got to know that ng-swith also works the same as ng-if, this will again cause me the same issue if datetime picker (won't work).

Is there any way to resolve this

My code structure -

<div id="mainDiv">
    <form id="myForm">

        <div ng-show="condition1">

            <div ng-if="condition1of1">
             // input fields such as text email password
            </div>

            <div ng-show="condition2of1">
            //date time picker here 
            </div>
            
            <div ng-if="condition3of1">
            // other input fields
            </div>

        </div>

        <div ng-if="condition2>......</div>

        <div ng-if="condition3>......</div>

        <input id="btn" type="submit" ng-disabled="myForm.$invalid" value="Submit" ng-click="submitData()"> // button that will remain disable until all the required fields will not get resolved.
    </form>
</div>

How to resolve this issue?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda