Change naming_series depending on voucher_type

i used a custom script to change the naming series value each time i select a voucher_type
it doesnt work. It only works when i replace custom_validate to custom_refresh but i need it to change everytime i change the voucher_type

 cur_frm.cscript.custom_validate = function(doc) {
    doc.naming_series = "";
    switch(doc.voucher_type) {
        case "Journal Entry":
            doc.naming_series = "JV.########";
            break;
        case "Bank Voucher":
            doc.naming_series = "CV.########";
            break;
        default:
            doc.naming_series = ""
    }
}
  1. What do i need to do to make it work

  2. How do i use custom_validate , i tried many custom script using custom_validate so far custom_validate is not working but all of the scripts that i have tried works on custom_refresh

Listed on voucher_type trigger