get right options with hooks

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
landrea
Posts: 27
Joined: 2018-08-04 13:09

get right options with hooks

Post by landrea » 2019-03-22 20:31

I'm working a hook using js files
it works, but it's only a concidence because I dont' have enough datas inside,
so at the moment the option1 is correctly what i need to check, but this can change with other datas

the problem is the value inside the option is not the foreign key as I thought (i made a test to see it), it seems is simply the list of the table in alphabetic order, the first element in this order

so, I pheraps need to check the label and go down and look the option associated the label if is checked, because the value inside the option is not connected directly any element of the foreign key


// INIZIALIZZA FUNZIONI
$j(function(){

// PREVIENE SALVATAGGIO SE CAMPO E' VUOTO - update
$j('#update').click(function(){

// VERIFICO
var verifica_radio_periferica = document.getElementById('tipologia_periferica1').checked;
var verifica_input_inchiostro = $j('#inchiostro_stampante').val();

// CASO STAMPANTE NON SELEZIONATA
if(verifica_input_inchiostro > 0 && verifica_radio_periferica !== true){
return show_error('Inchiostro stampante', 'Il campo inchiostro stampante richiede la selezione di una stampante');
}
// CASO STAMPANTE SELEZIONATA SENZA INCHIOSTRO
if(verifica_input_inchiostro == '' && verifica_radio_periferica === true){
return show_error('Inchiostro stampante', 'Il campo inchiostro stampante deve essere compilato per le stampanti');
}

}) // fine funzione update


// PREVIENE SALVATAGGIO SE CAMPO E' VUOTO - insert
$j('#insert').click(function(){

// VERIFICO
var verifica_radio_periferica = document.getElementById('tipologia_periferica1').checked;
var verifica_input_inchiostro = $j('#inchiostro_stampante').val();

// CASO STAMPANTE NON SELEZIONATA
if(verifica_input_inchiostro > 0 && verifica_radio_periferica !== true){
return show_error('Inchiostro stampante', 'Il campo inchiostro stampante richiede la selezione di una stampante');
}
// CASO STAMPANTE SELEZIONATA SENZA INCHIOSTRO
if(verifica_input_inchiostro == '' && verifica_radio_periferica === true){
return show_error('Inchiostro stampante', 'Il campo inchiostro stampante deve essere compilato per le stampanti');
}

}) // fine funzione update


}) // FINE FUNZIONE INIZIALIZZA

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: get right options with hooks

Post by pbottcher » 2019-03-24 13:16

Hi,

maybe you try to explain what you try to acheive. Posting a picture would possibly help as well.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

landrea
Posts: 27
Joined: 2018-08-04 13:09

Re: get right options with hooks

Post by landrea » 2019-03-24 22:12

I moved on, I wrote simple a note to compile the field only if otpion is "printer", I wanted to put a validation or hide the filed, etc..
this is simpler with list, because with list you have input hidden field with the value inside

the problem was that in the option list the value associated is 1, but this is not the foreign key, is the number of item from the foreign table in alphabetic order, so, if I add something in the table, the object "printer" is not anymore "1", so I can't intercept it in this way

one soluction I find is choose another order in appgini, in the sql you can chose another order, istead to write order by 2, you write order by 1 that is the id, in this case, since "printer" is id 1, also the option value is id 1 and I'm ok with my code

other soluction could be get the label with jquery or javascript, I think option is the next sbiling, so you can get all the collection o label, find the label "printer", go in the nex sibling and this is your option

I didn't make it this time, project is already finish, I'm ok this time, it's not necessary write too many hooks, next time I'm going to try in this way

Post Reply