1

How to add a title for the JqueryUI dialog box for this case. This dialog box opens as per the model name in ruby on rails.

Example of the html page:

<%= link_to pro_generic_lookup_data_path("Enr::Rds::Section2009", format: :js), data: {remote: true} %>

Here, the pro_generic_lookup_data is have the option of uidialog box. So, it would open depend upon the model name("Enr::Rds::Section2009").

JavaScript

var generic_lookup_Enr_Rds_Section2009_selected = function(id, to_s) {
  var section_value = $(".cross-reference-section-value");
  var section_id = $(".cross-reference-section-value-id");
  var section_clear_img = $(".cross-reference-section-clear-img");
  section_id.val(id);
  section_value.text(to_s);
  section_value.css('display', 'inline');
  section_clear_img.css('display', 'inline');
  $(section_clear_img).on('click', function() {
    section_value.text('')
    section_id.val('')
    section_clear_img.css('display', 'none');
  });
  var question_link = $('#question_picker').attr('href');
  question_link = question_link.replace(/\?+$/, '');
  question_link = question_link + '?columns[enr_rds_section_id]=' + id;
  $('#question_picker').attr('href', question_link);
  $("#modal_popup").dialog("destroy");      
};

I have three fields like this same. So, I need to give a separate titles for all the three fields. Thanks!

1

1 Answer 1

2

Other than some basic formatting and using chained selectors where applicable, the code is fine.

var generic_lookup_Enr_Rds_Section2009_selected = function(id, to_s) {
    var $section_value = $(".cross-reference-section-value");
    var $section_id = $(".cross-reference-section-value-id");
    var $section_clear_img = $(".cross-reference-section-clear-img");

    $section_id.val(id);    
    $section_value.text(to_s).css('display', 'inline');

    $section_clear_img.css('display', 'inline').on('click', function() {
        $section_value.text('')
        $section_id.val('')
        $section_clear_img.css('display', 'none');
    });

    var question_link = $('#question_picker').attr('href');
    question_link = question_link.replace(/\?+$/, '');
    question_link = question_link + '?columns[enr_rds_section_id]=' + id;
    $('#question_picker').prop('href', question_link);

    $("#modal_popup").dialog("destroy");      
};
Sign up to request clarification or add additional context in comments.

3 Comments

Does we need the dollar sign after we declared the variable?
It is the marker for indication that we store jquery object. Kind of nice jquery code style
Thanks Roman! I have an issue with the question picker of this javascript. The question_picker add the section_id of the existing href. After reselect the section_id, the question_picker doesn't change the section-id. How to resolve this? Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.