Skip to content

setContent for a dialog box #10

Open
capripot opened this Issue Aug 30, 2010 · 11 comments

2 participants

@capripot

Hi everybody
I'm not shure if it correspond to the project philosophy
but i think it could be very cool to have a method "setContent" to refresh the content of dialog box.
is it a good idea ? i've made some code to illustrate :

setContent: function(new_content) {
    if(new_content){
      this.content = Object.isElement(new_content) ? new_content :
      new Element('div').update(new_content);
    }else{
      new_content = new Element('div');
    }
    this.element.select('.ui-widget-content').first().update(new_content);
},
@justbaker

Why are you creating a new div element? And why insert it at all if new_content wasn't even supplied as an argument?

@capripot

A new div because it is designed as it in the original code I think.
And I always insert it because I believe it's better to keep the same design.

@justbaker

The content is inserted in "ui-dialog-content" div, and isn't padded at all by an extra div.
Inserting new div's every time the content is change wouldn't really be a good idea.

@capripot

If you want to insert some text directly, you have to wrap it in a div element, isn't it ?

@justbaker

Actually, I'm wrong.
What you're doing is inserting another div into the content div rather than updating the content inside the content div.

setContent: function(new_content) {
if(new_content){
this.element.select('.ui-widget-content').first().update(new_content);
}
},

Wouldn't that accomplish it?

@capripot

Yes it's right,
but if don't want to insert a div element and just add a message, so just some text like
mydialog.setContent("Bonjour world"); i think we have to add a wrapper, it's why I verified if new_content was an element (a div or whatever) or a text node with the first condition.

@justbaker

No, with the above code I posted it would update the innerHTML of the content. No wrapper needed.

@capripot

Yes but sometimes there is no "first" in the ".ui-widget-content" div.

@justbaker

That would mean that no content was supplied originally. Also, wouldn't ".ui-dialog-content" be better? The content div has both classes.

@capripot

Yes, so you have to had a div no ?
".ui-dialog-content" could be better yes :)

@justbaker

I would see if the content is blank, and if so, create the dialog-content div and insert it into the dialog's element, otherwise change the value of the dialog-content div

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.