[Html-widget] trying to get the type of an element

John Napiorkowski jjn1056 at yahoo.com
Wed Nov 15 17:18:04 GMT 2006


--- Carl Franks <fireartist at gmail.com> wrote:

> On 15/11/06, John Napiorkowski <jjn1056 at yahoo.com>
> wrote:
> >
> > --- Carl Franks <fireartist at gmail.com> wrote:
> >
> > > On 14/11/06, John Napiorkowski
> <jjn1056 at yahoo.com>
> > > wrote:
> > > > Okay,
> > > >
> > > > This is probably not the smartest question,
  > but
> > > I've
> > > > looked at the source and the docs and I can't
> > > figure
> > > > out how to get the type of an element.  I just
> > > can't
> > > > say:
> > > >
> > > > $element->type;
> > > >
> > > > or any other combination I can think of. 
> There
> > > must
> > > > be a way to do this.  Anyone know?
> > >
> > > The only way to get that just now would be ref(
> > > $element )
> > > but that would give something like
> > > 'HTML::Widget::Element::Textfield'
> > >
> > > You could use add a new method to H/W/Elements
> with
> > > mk_accessors()
> > > and then edit H/Widget::element() to store the
> type
> > > it receives, using
> > > that method after it's created the element.
> > > Unfortunately, both Block and Button already
> have a
> > > 'type' method, so
> > > it'll need to be a different name - I can't
> really
> > > think of anything
> > > else that's suitable, as 'type' would be most
> > > appropriate.

I'm doing this with 'element_type' as the accessor.  I
got this to work with element right off the form tree,
like so:

my $w1	= HTML::Widget->new;
my $f1	= $w1->element('Fieldset', 'top');
my $e1	= $f1->element('Textfield', 'tfone');

is(
     $f1->element_type,
     'Fieldset',
     'Checking element_type accessor'
);  ## PASSED

is(
     $e1->element_type,
     'Textfield',
     'Checking element_type accessor'
); ##FAILED

The second test fails though..  I don't think updating
the element method in HTML::Widget::Element is enough
to set the accessor properly, looks like there is
something to do in HTML::Widget::Container as well,
although I'm still new to the source.  Does anyone
know which package has the element method that gets
called when an element object calls it's element
method?

--John


> > >
> > > Carl
> >
> > How about "form_tag" or "form_element" or
> > "tag|element_name"?
> 
> Not anything with 'tag', as the element types don't
> map to HTML tag names:
> I suggest 'element_type' so it's clear it's specific
> to HW.
> 
> Carl
> 
> _______________________________________________
> Html-widget mailing list
> Html-widget at lists.rawmode.org
>
http://lists.rawmode.org/cgi-bin/mailman/listinfo/html-widget
> 



 
____________________________________________________________________________________
Sponsored Link

$200,000 mortgage for $660/ mo - 
30/15 yr fixed, reduce debt - 
http://yahoo.ratemarketplace.com



More information about the Html-widget mailing list