8
I did some research on the net, I found this website with valuable information. I work a lot with conditionals using javascript, see an excerpt of my function that receives radiogroup as a parameter and checks whether it was selected yes or no, thus performing the proper tasks:
var habilitarCampo3 = function(obj, selectedRadio)
{
if(selectedRadio.inputValue == "NAO"){
Ext.getCmp('comJustificativaAviso').setVisible(true);
if (iAtividade == 7)
{
TransitionData2Form.insertMandatory('comJustificativaAviso','Justifique o não desconto do Aviso Prévio!');
}
}
else{
Ext.getCmp('comJustificativaAviso').setVisible(false);
TransitionData2Form.removeMandatory('comJustificativaAviso');
Ext.getCmp('comJustificativaAviso').setValue(Ext.getCmp('procedeJuridico').getValue().inputValue);
}
};
Sometimes this code stays on the radiogroup object itself, see:
checkSolicitacoesRealizadas = new Ext.form.RadioGroup
({
width:600,
fieldLabel:'Solicitações foram realizadas',
labelSeparator: '?',
id:'checkSolicitacoesRealizadas',
value:'ZERO',
listeners:
{
change: function(obj, selectedRadio)
{
if (selectedRadio.inputValue == "NAO")
{
alert('É obrigatório a geração das solicitações');
Ext.getCmp('checkSolicitacoesRealizadas').setValue('ZERO');
}
}
},
items: [
{boxLabel: '<b style="color:green;" >Sim</b>', name: 'checkSolicitacoesRealizadas-op', inputValue: "SIM"},
{boxLabel: '<b style="color:green;" >Sim</b>', hidden:true, name: 'checkSolicitacoesRealizadas-op', inputValue: "ZERO"},
{boxLabel: '<b style="color:red;" >Não</b>', name: 'checkSolicitacoesRealizadas-op', inputValue: "NAO"}
]
});
Here one of the hundreds of conditionals in my code:
if (Ext.getCmp('tipoRescisao').getValue() == 02 &&
Ext.getCmp('tipoSolicitacao').getValue().inputValue == 'desligamento')
{
if (Ext.getCmp('dataInicioAvisoPrevio').getValue() == '')
{
msgErro += "\n É Obrigatório [Data Início Aviso Prévio]!";
}
}
My question is: Is there any Design Patterns that treats a better way to organize conditional structures, performing some code use while comparing the value of the field? I wanted to organize a dynamic and intelligent structure to perform the value comparisons of form fields. I hope I was clear in the question. Any doubt I improve the question, this is very important to me.
I’m ready to signal as "based on opinions" by the part you say "best way to organize structures" but I think we can take advantage of this question, just change this part to "could introduce me some design Partner" so you can see the shapes yourself "different" to do the same thing, and then p/ front you choose the one you find most convenient ;)
– SneepS NinjA
"There is some Design Patterns that treats a better way to organize conditional structures, ...." Thank you for your attention. I think that’s a really valid question. When I say "Organize Better," I seek a concept that treats excessive use of if’s, I need an alternative. Your answer does not address this question of if’s.
– durtto
The question of if, is just make a call to a function from outside the object and make all the validations in another function, the if are not in the answer, but the function call concept yes
– SneepS NinjA
There is the jQuery library, Angular JS and React that can help you a lot in all this suffering. And there are many more answers to your question on the Mozilla website: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
– Ivan Ferrer