Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Selecionar checkbox consoante select

Participant ,
Mar 17, 2025 Mar 17, 2025

Boa noite a todos, ca estou eu a pedir a vossa preciosa ajuda.

Tenho um campo select com o nome de "tipo_servico" e vários checkbox com os nome exemplos (total, parcial, noturno, etc)

fiz o script abaixo e coloquei no campo tipo_servico em "Ações" quando o select perder o foco executar o script:

 

// Obtém o resultado do campo 'select' e seleciona o 'checkbox' correspondente
var campo1 = this.getField('tipo_servico');
var checkbox1 = this.getField('total');
var checkbox2 = this.getField('parcial');

// Função para verificar a seleção e marcar/desmarcar o checkbox2
campo1.setAction('Keystroke', function() {
    // Usando switch para verificar o valor selecionado no campo1
    switch(campo1.value) {
        case 'total':
            // Marca o checkbox total quando 'total' for selecionado
            checkbox1.checkThisBox(0, true);
            break;
        case 'parcial':
            // Marca o checkbox parcial quando 'parcial' for selecionado
            checkbox2.checkThisBox(0, true);
            break;
        default:
            // Caso nenhum item específico seja selecionado, desmarcar os checkbox
  checkbox1.checkThisBox(0, false);          
checkbox2.checkThisBox(0, false);
            break;
    }
});

Mas não funciona, o que fiz de errado? 

TOPICS
General troubleshooting , How to , JavaScript , PDF , PDF forms
352
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Participant ,
Mar 24, 2025 Mar 24, 2025
LATEST

Deixo aqui o que faltava para funcionar, não sei se foi o que indicaram.

Todas as respostas estão correctas, mas faltava selecionar o campo da imagem.Captura de ecrã 2025-03-24, às 19.11.17.png

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 17, 2025 Mar 17, 2025

Check the Javascript console for errors.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 17, 2025 Mar 17, 2025

Esse é o erro:
SyntaxError: function statement requires a name

1:Field:Keystroke

SyntaxError: function statement requires a name

1:Field:Keystroke

SyntaxError: function statement requires a name

1:Field:Keystroke

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 17, 2025 Mar 17, 2025

You didn't name the function.  MyFunction function().  You also need to run the function after defining it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 17, 2025 Mar 17, 2025

If you wish to use script as 'On Blur' you can use this:

var campo1 = event.target.value;
var checkbox1 = this.getField('total');
var checkbox2 = this.getField('parcial');

checkbox1.checkThisBox(0,(campo1 == "total")? true : false);
checkbox2.checkThisBox(0,(campo1 == "parcial")? true : false);
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 17, 2025 Mar 17, 2025

talvez para duas opções, sim.

Mas caso seja um select com 5 ou mais tipos de seleções talvez seja melhor usar o case

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 17, 2025 Mar 17, 2025

também da o mesmo erro.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 17, 2025 Mar 17, 2025

The cScript paramater of the field setAction method must be in quotes and you either have to remove all the line breaks, or concatenate all of them with + and quotes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 20, 2025 Mar 20, 2025

Boa tarde, penso eu que fiz tudo correcto.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 20, 2025 Mar 20, 2025

Why do you use setAction in the script?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 20, 2025 Mar 20, 2025

No, that is not correct.  You didn't follow what I said.  Echoing @Bernd Alheit , why use setAction in the script?  setAction is a way to modify the actions of a field without using the user interface, in the console, Action, or custom toolbar button for example.  You can simple add your script as validation script without using setAction.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 20, 2025 Mar 20, 2025

Vejá se fiz correcto agora, mas se fiz, mesmo assim não dá

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 24, 2025 Mar 24, 2025
LATEST

Deixo aqui o que faltava para funcionar, não sei se foi o que indicaram.

Todas as respostas estão correctas, mas faltava selecionar o campo da imagem.Captura de ecrã 2025-03-24, às 19.11.17.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines