Certain function does not work in Firefox

Asked

Viewed 758 times

2

I got a parole like that:

     // 1.º - Verificar se existe a matrícula no sistema
                 function existeColaborador()
                     {
                         if(DSdetalhesColaborador.values[0] == undefined)
                             {
                        //alert('Matricula inválida');
                        limpaCampos();
                        return false;
                    }
                         else
                             {
                        if ((DSibrr.values.length < 1) && (DSdetalhesColaborador.values[0]['Situacao'] == 'A'))
                            {
                            return true;
                            }
                    }
                     } // fim da função

And then down in the code I have my function:

     if(existeColaborador() == false)
                {
                alert('Não existe Colaborador com essa matrícula')
                }
                else
                {
                  // DSdetalhesColaborador.values[0]['Situacao'] = 'D';

               if (tipoSolicitacao == 'complementar')
                    {
                     if (DSdetalhesColaborador.values[0]['Situacao'] == 'A')
           {
                         alert("Não é possível realizar uma Rescisão Complementar para um Colaborador ATIVO!");
                         limpaCampos();
                         }
                   else if  (DSdetalhesColaborador.values[0]['Situacao'] == 'D' && DSibrr.values.length > 0)
                     {
                      if  (DSdetalhesColaborador.values[0]['Situacao'] == 'D' && DSibrr.values[0]['tipoSolicitacao'] == 'complementar')
                       {

                                                 Ext.Msg.show({
                                msg: "Colaborador já está em processo de demissão no ECM. Iniciar novo Processo Complementar para o colaborador?",
                                buttons: Ext.Msg.YESNO,
                                icon: Ext.MessageBox.ERROR,
                                fn: function(btn) {
                                        console.log(arguments);
                                        if (btn == 'yes') {
                                        preencheCampos()
                                        }
                                        else
                                        {
                                        limpaCampos()
                                        }
                                }
                        });
                         //alert('O Colaborador já teve um processo demissão iniciado ou finalizado no ECM!');
              //preencheCampos();
                       }
                      else if  (DSdetalhesColaborador.values[0]['Situacao'] == 'D' && DSibrr.values[0]['tipoSolicitacao'] == 'desligamento')
                       {
                           preencheCampos();
                         }
                     }
                     else
                 {
                         alert('O Colaborador ainda não tem um processo demissão iniciado ou finalizado no ECM!');
                         preencheCampos();
                     }


                    }
      } // fim da condicional

It turns out that in Chrome everything works fine, but in firefox error occurs saying:

existeColaborador is not defined.

Is there any problem in calling a function within a conditional?

Following file Rules

image shows my code

inserir a descrição da imagem aqui

This image shows the firefox error:inserir a descrição da imagem aqui

  • Because there’s a change of identation on line 478?

  • In line 478 there is an instructive comment. Above it I consume web services and store the values in objects. Later I need to make a series of comparisons of these values, because I depend on various information of these webservices. Example: I enter the employee registration, if this employee == fired, I do not allow you to resign.

  • Do you want to solve the problem or know why it’s going wrong just in the firefox?

  • Okay, Sergio, after I correct the tab, but now I need to understand why firefox does not recognize the function. help me.

  • I want to understand @Jéfersonbueno, understood I seek the fix.

  • You have how to post the full code of functions?

  • @Eduardoseixas but I see no reason to change the indent after a comment... You can reproduce the problem in jsFiddle for example?

  • @Eduardoseixas, post the function code. We have no way to guess what is causing the error...

  • Try passing the function over the code that calls it. Also try clearing the browser cache and inspect if your code has been updated.

  • OK @Joaopaulo I will try to do this, but I want it to work regardless of where the function is... It could even be in another file, it should run, because, remembering, it runs on 'Chrome' but does not work on 'firefox'.

  • Passing the function up solved. But because firefox does not understand in the same way as Chrome?

  • @Eduardoseixas If possible, we need all the code from Rules.js, if it is not too difficult to guess by looking only at the image. As we know the browser reads the entire file before running so the problem may be elsewhere than you can imagine, so we need to see all the code to give you an answer.

  • It’s a lot, but okay....

  • [follow Rules] (http://jsfiddle.net/Durtto/4u82whaf)

  • @Eduardoseixas check your browser version and more importantly if by chance there is no other javascript that happens to have another function or variable with the same name of this function. Because I ran here in firefox only the chunk with error, and it works normally (it does not from Function Undefined error) even with me passing its validation function to after if, because in javascript this is irrelevant since Function is in the same closure of if.

  • Run a simple test. Rename the function to something that you can be sure is not nearly impossible to use on the system, for example testadasd() and see if the error continues.

  • I changed yes, but it won’t help anyway. Check out this answer. firefox doesn’t really support block function statement.. http://stackoverflow.com/questions/25111087/why-is-a-function-declaration-within-a-condition-block-hoisted-to-function-scope

Show 12 more comments

2 answers

3


There are several reasons that can make your code not work, here are some tips:

  • Try passing the function over the calling code.

  • Clear the browser cache and Inspecione if your code has been updated.

  • Finish all your scripts with ";" at the end. (I see there is an Alert() without ;)

Note: Older browser versions sometimes do not interpret in the same way as more current ones.

0

This error occurs when the function has not been declared before loading the page, try to include Rules.js file in your View:

<script src="../10000/rules.js"></script>

or declare the function before loading the page.

  • 1

    From what I understand the function is declared in the same file, and in the image } is there.

  • it really gets complicated to guess how the structure is there, but if it is in the same file, just create a script tag before the page startup, type text/javascript and declare this function existeColaborator there, it has to work.

  • Are you sure the script functionary in the Chrome if it was not referenced in the html?

  • It is referenced yes, I already checked.. the Rules file contain the rule.

Browser other questions tagged

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