var $ = require('jQuery');
var fieldRegistry = require('kwf/frontend-form/field-registry');
var Field = require('kwf/frontend-form/field/field');
var kwfExtend = require('kwf/extend');

var Radio = kwfExtend(Field, {
    initField: function() {
        this.el.find('input').each((function(index, input) {
            $(input).on('click', (function() {
                this.el.trigger('kwfUp-form-change', this.getValue());
            }).bind(this));
        }).bind(this));
    },
    getValue: function() {
        var ret = null;
        this.el.select('input').each(function(index, input) {
            if (input.checked) {
                ret = input.value;
            }
        });
        return ret;
    },
    clearValue: function() {
        this.el.select('input').each(function(index, input) {
            input.checked = false;
        });
    },
    setValue: function(value) {
        this.el.select('input').each(function(index, input) {
            if (input.value == value) {
                input.checked = true;
            } else {
                input.checked = false;
            }
        });
    }
});

fieldRegistry.register('kwfFormFieldRadio', Radio);
module.exports = Radio;

var $ = require('jQuery');
var fieldRegistry = require('kwf/frontend-form/field-registry');
var Field = require('kwf/frontend-form/field/field');
var kwfExtend = require('kwf/extend');

var Radio = kwfExtend(Field, {
    initField: function() {
        this.el.find('input').each((function(index, input) {
            $(input).on('click', (function() {
                this.el.trigger('kwfUp-form-change', this.getValue());
            }).bind(this));
        }).bind(this));
    },
    getValue: function() {
        var ret = null;
        this.el.find('input').each(function(index, input) {
            if (input.checked) {
                ret = input.value;
            }
        });
        return ret;
    },
    clearValue: function() {
        this.el.select('input').each(function(index, input) {
            input.checked = false;
        });
    },
    setValue: function(value) {
        this.el.select('input').each(function(index, input) {
            if (input.value == value) {
                input.checked = true;
            } else {
                input.checked = false;
            }
        });
    }
});

fieldRegistry.register('kwfFormFieldRadio', Radio);
module.exports = Radio;

Fix Radio: Use find, select does not return all inputs.
Fix Radio: Use find, select does not return all inputs.

getValue didn't work
