make checkbox persistence work properly
Tara L Andrews [Fri, 8 Jun 2012 10:35:42 +0000 (12:35 +0200)]
stemmaweb/root/js/relationship.js

index 3fa40d1..ed43d5d 100644 (file)
@@ -52,8 +52,8 @@ function node_dblclick_listener( evt ) {
        // Set the easy properties first
        $('#reading-form').dialog( 'option', 'title', 'Reading information for "' + reading_info['text'] + '"' );
        $('#reading_id').val( reading_id );
-       $('#reading_is_nonsense').attr( 'checked', reading_info['is_nonsense'] );
-       $('#reading_grammar_invalid').attr( 'checked', reading_info['grammar_invalid'] );
+       toggle_checkbox( $('#reading_is_nonsense'), reading_info['is_nonsense'] );
+       toggle_checkbox( $('#reading_grammar_invalid'), reading_info['grammar_invalid'] );
        // Use .text as a backup for .normal_form
        var normal_form = reading_info['normal_form'];
        if( !normal_form ) {
@@ -71,6 +71,13 @@ function node_dblclick_listener( evt ) {
        $('#reading-form').dialog("open");
 }
 
+function toggle_checkbox( box, value ) {
+       if( value == null ) {
+               value = false;
+       }
+       box.attr('checked', value );
+}
+
 function morphology_form ( lexlist ) {
        $('#morphology').empty();
        $.each( lexlist, function( idx, lex ) {