import { BoundItemAttribute } from "../BoundItemAttribute" ; import { UkuleleUtil } from "../../util/UkuleleUtil" ; export class BountItemAttrSelected extends BoundItemAttribute { constructor ( attrName , ukuTag , element , uku ) { if ( ukuTag !== "selected" ) { throw new TypeError ( "it doesn't use uku-selected" ) ; } super ( attrName , ukuTag , element , uku ) ; } render ( controllers ) { let attr = this . attributeName ; let key ; let elementName = this . element . tagName ; if ( elementName === "SELECT" ) { let tempArr = this . attributeName . split ( "|" ) ; attr = tempArr [ 0 ] ; key = tempArr [ 1 ] ; let finalValue = UkuleleUtil . getFinalValue ( controllers , attr ) ; let value ; if ( key ) { value = finalValue [ key ] ; } else { value = finalValue ; } ( this . element as HTMLSelectElement ) . value = value ; } if ( elementName === "INPUT" && this . element . getAttribute ( "type" ) === "radio" ) { let finalValue = UkuleleUtil . getFinalValue ( controllers , attr ) ; if ( ( this . element as HTMLInputElement ) . value === finalValue ) { ( this . element as HTMLInputElement ) . setAttribute ( "checked" , "true" ) ; } } } }