From 2518612b0de13b3fd09eee7731804d077ded4ccf Mon Sep 17 00:00:00 2001 From: Adam Young Date: Tue, 1 Feb 2011 18:01:19 -0500 Subject: core widget unit tests baseline set of unit tests for checking that each widget conforms to the contract --- install/ui/widget.js | 69 +++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 36 deletions(-) (limited to 'install/ui/widget.js') diff --git a/install/ui/widget.js b/install/ui/widget.js index 8c080787b..9f6365a0b 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -282,7 +282,7 @@ IPA.text_widget = function(spec) { if(that.undo){ that.show_undo(); } - var value = $('input[name="'+that.name+'"]', that.container).val(); + var value = $(this).val(); that.validate_input(value); }); @@ -520,10 +520,21 @@ IPA.radio_widget = function(spec) { }; that.update = function() { - if (that.values && that.values.length) { - var input = $('input[name="'+that.name+'"][value="'+that.values[0]+'"]', that.container); + + + + if (that.values) { + var value; + if ((that.values instanceof Array ) && that.values.length){ + value = that.values[0] + }else{ + value = that.values; + } + + var input = $('input[name="'+that.name+'"][value="'+value+'"]', + that.container); if (input.length) { - input.get(0).checked = true; + input.attr('checked', true); return; } } @@ -637,6 +648,13 @@ IPA.textarea_widget = function (spec) { if (that.undo) { that.create_undo(container); } + + $("",{ + name:'error_link', + html:"Text does not match field pattern", + "class":"ui-state-error ui-corner-all", + style:"display:none" + }).appendTo(container); }; that.setup = function(container) { @@ -646,6 +664,10 @@ IPA.textarea_widget = function (spec) { var input = $('textarea[name="'+that.name+'"]', that.container); input.keyup(function() { undo.css('display', 'inline'); + + var value = $(this).val(); + that.validate_input(value); + }); var undo = that.get_undo(); @@ -677,35 +699,6 @@ IPA.textarea_widget = function (spec) { return that; }; -IPA.button_widget = function (spec) { - - spec = spec || {}; - - spec.setup = spec.setup || setup; - spec.load = spec.load || load; - spec.save = spec.save || save; - - var that = IPA.widget(spec); - - that.click = spec.click; - - function setup(container) { - - that.widget_setup(container); - - var input = $('[name="'+that.name+'"]', that.container); - input.replaceWith(IPA.button({ 'label': that.label, 'click': that.click })); - } - - function load(record) { - } - - function save() { - return []; - } - - return that; -}; IPA.column = function (spec) { @@ -1066,19 +1059,23 @@ IPA.entity_select_widget = function(spec){ var that = IPA.widget(spec); var entity = spec.entity || 'group'; + var field_name = spec.field_name || 'cn'; function populate_select(value){ function find_success(result){ $('option', that.entity_select).remove(); var entities = result.result.result; for (var i =0; i < result.result.count; i +=1){ + var entity = entities[i]; + var field_array = entity[field_name]; + var field_value = field_array[0]; var option = $('