ArmadoDeForm.js 1.41 KB
var getAncestorByAttribute = (elem,attr,val) => {
    while (elem.getAttribute(attr) != val || elem == null) elem = elem.parentElement;
    return elem;
}

var getDescendantByAttribute = (elem,attr,val) => {
    if (elem == null || elem.getAttribute(attr) == val) return elem;
    return Array.from(elem.children).reduce( (a,b) => {
        let x = getDescendantByAttribute(a,attr,val);
        let y = getDescendantByAttribute(b,attr,val);
        return x == null ? y : x;
    }, null);
}

function HabilitarTab(bc,tc,n){
    if (typeof n != "number") return console.log("El entero es invalido");

    for (let it = 0; it < bc.children.length && it < tc.children.length; it++) {
        if (it == n) {
            bc.children[it].classList.add("BotonesActive");
            tc.children[it].style.display = "block";
        } else {
            bc.children[it].classList.remove("BotonesActive");
            tc.children[it].style.display = "none";
        }
    }
}

function Otro(otroselect){
    let inputs = getAncestorByAttribute(otroselect,"class","FieldInput");
    let other = getDescendantByAttribute(inputs,"class","Other");
    if (otroselect.nodeName == "SELECT"){
        if (otroselect.selectedOptions[0].value == "Otro") other.style.display = "block";
        else other.style.display = "none";
    }
    else {
        if (otroselect.checked) other.style.display = "block";
        else other.style.display = "none";
    }
}