Nice! This would be doubly handy if it returned all matching
components (jQuery style). What about adding a first=True arg to make
return all matches optional ? (or some other more graceful solution
that I'm sure you've already thought of before finishing this
sentence :)
def element(self, first=True, **kargs):
components = copy.copy(self.components)
matches = []
for c in components:
try:
components += copy.copy(c.components)
check = True
for (key, value) in kargs.items():
if c[key] != value:
check = False
if check:
if first:
return c
else:
matches.append(c)
except:
pass
if len(matches): return matches
return None
On Oct 11, 2:04 pm, mdipierro <[email protected]> wrote:
> It is there already
>
> form.element(_type='submit')['_style']="color:white; background-
> color:blue; font-weight:bold"
>
> It only finds the first matching element.
>
> On Oct 11, 1:16 pm, "mr.freeze" <[email protected]> wrote:
>
> > >Good point - and addresses the original post (as it could have been more
> > >simply done this way);
>
> > Not technically since this would affect everything inside the form and
> > not just the submit button. What about a member function 'find' added
> > to XmlComponent or DIV (which I think most helpers inherit from) that
> > allows you to traverse the inner components and return the matching
> > components for given criteria. The pseudo-code might look like this:
>
> > submit = form.components.find(XML.attribute("type")=="submit")[0]
> > submit['_style'] = "color:white; background-color:blue; font-
> > weight:bold"
>
> > On Oct 11, 12:29 pm, Yarko Tymciurak <[email protected]> wrote:
>
> > > On Sun, Oct 11, 2009 at 11:04 AM, mdipierro <[email protected]>
> > > wrote:
>
> > > > I do not think you cannot use decorators this way.
>
> > > double negatives.... not sure what you intended to say (but logical
> > > analysis
> > > says "... think you can use decorators this way...");
>
> > > > But I remind you crud.create is a function that returns SQLFORM which
> > > > is a FORM which is a heper as any other helper. Therefore you can do:
>
> > > > form = crud.create(...)
> > > > form['_style']="color:white; background-color:blue; font-weight:bold"
>
> > > Good point - and addresses the original post (as it could have been more
> > > simply done this way);
>
> > > Regardless, then
>
> > > @style( color='white', background-color='blue', font-weight='bold')
> > > form = crud.create(...)
>
> > > would still be a readable thing (and just trivial to implement);
>
> > > Alternatively, form.style( ...same kinds of parameters....) could be
> > > used;
>
> > > Anyway, this is about readability, and ease of infding this stuff (as this
> > > post shows);
>
> > > If there were a member function to FORM to set style, people who not have
> > > to
> > > stumble upon it.
>
> > > Thoughts?
>
> > > > On Oct 11, 10:47 am, Web2py-SuperFan <[email protected]> wrote:
> > > > > I really like that suggestion, would be much cleaner code and easier
> > > > > to configure different styles that have meaning by variable name
>
> > > > > On Oct 10, 9:47 pm, Yarko Tymciurak <[email protected]> wrote:
>
> > > > > > I wonder if we could encapsulate, simplify this with a decorator,
> > > > something
> > > > > > like:
>
> > > > > > @button( color='white', background='blue', font='bold' )
> > > > > > form = crud.create(...)
>
> > > > > > Something like this could be useful for something like
>
> > > > > > @button( my_admin_style )
> > > > > > form = crud.create(....)
>
> > > > > > @button( my_warning_style )
> > > > > > form = ...
>
> > > > > > .... just thinking out loud....
>
> > > > > > On Sat, Oct 10, 2009 at 11:10 PM, Web2py-SuperFan
> > > > > > <[email protected]
> > > > >wrote:
>
> > > > > > > took me a while to dig up the answer/solution, maybe can save
> > > > > > > someone
> > > > > > > else some time
>
> > > > > > > form = crud.create(...)
> > > > > > > form=DIV(
> > > > > > > form,
> > > > > > > SCRIPT('''$(document).ready(function() {
> > > > > > > $("input[type=submit]").val("Share");
> > > > > > > });'''),
> > > > > > > SCRIPT('''$(document).ready(function() {
> > > > > > > $("input[type=submit]").css({
> > > > > > > color:'white',
> > > > > > > background:'blue',
> > > > > > > font: 'bold'});
> > > > > > > });'''),
> > > > > > > )
>
> > > > > > > return dict(form=form)- Hide quoted text -
>
> > > > > > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---