diff --git a/docs/migration.txt b/docs/migration.txt
index 575008fe0..1cf89f35a 100644
--- a/docs/migration.txt
+++ b/docs/migration.txt
@@ -424,6 +424,11 @@ $f->text({-name=>"nameGoesHere"});
$f->text(name=>"nameGoesHere");
$f->text({name=>"nameGoesHere"});
+Also every form control now has an auto-generated ID attribute to aid in the
+swift development of AJAX features. You can override the autogenerated one by
+passing in an id parameter like this:
+
+$f->text(name=>"this",id==>"myownpersonalid");
+
See WebGUI::HTMLForm and WebGUI::Form::Control for additional information.
-
diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm
index f0282ccab..bace93ff7 100644
--- a/lib/WebGUI/Asset.pm
+++ b/lib/WebGUI/Asset.pm
@@ -2979,7 +2979,8 @@ sub www_editTree {
-subtext=>' '.WebGUI::International::get("change","Asset").' '.WebGUI::Form::yesNo({name=>"change_url"}),
-value=>WebGUI::Form::selectList({
name=>"baseUrlBy",
- extras=>'id="baseUrlBy" onchange="toggleSpecificBaseUrl()"',
+ extras=>'onchange="toggleSpecificBaseUrl()"',
+ id=>"baseUrlBy",
options=>{
parentUrl=>"Parent URL",
specifiedBase=>"Specified Base",
diff --git a/lib/WebGUI/Asset/Wobject/Navigation.pm b/lib/WebGUI/Asset/Wobject/Navigation.pm
index 7a69225f8..54a967a24 100644
--- a/lib/WebGUI/Asset/Wobject/Navigation.pm
+++ b/lib/WebGUI/Asset/Wobject/Navigation.pm
@@ -120,7 +120,8 @@ sub getEditForm {
-value=>[$self->getValue("startType")],
-label=>$i18n->get("Start Point Type"),
-hoverHelp=>$i18n->get("Start Point Type description"),
- -extras=>'id="navStartType" onChange="changeStartPoint()"'
+ -id=>"navStartType",
+ -extras=>'onchange="changeStartPoint()"'
);
$tabform->getTab("properties")->readOnly(
-label=>$i18n->get("Start Point"),
diff --git a/lib/WebGUI/Form/Control.pm b/lib/WebGUI/Form/Control.pm
index 3fa1ac7c7..79a6f5759 100644
--- a/lib/WebGUI/Form/Control.pm
+++ b/lib/WebGUI/Form/Control.pm
@@ -89,6 +89,10 @@ Add extra attributes to the form tag like
A text label that will be displayed if toHtmlWithWrapper() is called.
+=head4 id
+
+A unique identifier that can be used to identify this field with javascripts and cascading style sheets. Is autogenerated if not specified. The autogenerated version is the value of the name parameter concatinated with the string "_formId". So for a field called "title" it would be "title_formId".
+
=head4 uiLevel
The UI Level that the user must meet or exceed if this field should be displayed with toHtmlWithWrapper() is called.
@@ -159,6 +163,9 @@ sub definition {
defaultValue=>undef
},
subtext=>{
+ defaultValue=>undef
+ },
+ id=>{
defaultValue=>undef
}
});
@@ -167,6 +174,24 @@ sub definition {
#-------------------------------------------------------------------
+=head2 generateIdParameter ( name )
+
+A class method that returns a value to be used as the autogenerated ID for this field instance. Unless overriden, it simply returns the name with "_formId" appended to it.
+
+=head3 name
+
+The name of the field.
+
+=cut
+
+sub generateIdParameter {
+ my $class = shift;
+ my $name = shift;
+ return $name."_formId";
+}
+
+#-------------------------------------------------------------------
+
=head2 getName ( )
Returns a human readable name for this form control type. You MUST override this method with your own when creating new form controls.
@@ -323,6 +348,10 @@ sub new {
unless (exists $params{value}) {
$params{value} = $params{defaultValue};
}
+ # doesn't have an id specified, so let's give it one
+ unless ($params{id}) {
+ $params{id} = $class->generateIdParameter($params{name});
+ }
bless \%params, $class;
}
diff --git a/lib/WebGUI/Form/HTMLArea.pm b/lib/WebGUI/Form/HTMLArea.pm
index f7c3deafc..0f435c16f 100644
--- a/lib/WebGUI/Form/HTMLArea.pm
+++ b/lib/WebGUI/Form/HTMLArea.pm
@@ -122,8 +122,8 @@ Renders an HTML area field.
sub toHtml {
my $self = shift;
WebGUI::Style::setScript($session{config}{extrasURL}.'/textFix.js',{ type=>'text/javascript' });
- $self->{extras} .= ' id="'.$self->{name}.'" onBlur="fixChars(this.form.'.$self->{name}.')" mce_editable="true" ';
- return $self->SUPER::toHtml.WebGUI::Asset::RichEdit->new($self->{richEditId})->getRichEditor($self->{name});
+ $self->{extras} .= ' onblur="fixChars(this.form.'.$self->{name}.')" mce_editable="true" ';
+ return $self->SUPER::toHtml.WebGUI::Asset::RichEdit->new($self->{richEditId})->getRichEditor($self->{id});
}
diff --git a/lib/WebGUI/Form/asset.pm b/lib/WebGUI/Form/asset.pm
index f5d747311..b0f87dcc4 100644
--- a/lib/WebGUI/Form/asset.pm
+++ b/lib/WebGUI/Form/asset.pm
@@ -109,17 +109,19 @@ sub toHtml {
my $asset = WebGUI::Asset->newByDynamicClass($self->{value}) || WebGUI::Asset->getRoot;
return WebGUI::Form::hidden->new(
name=>$self->{name},
- extras=>'id="'.$self->{name}.'" '.$self->{extras},
- value=>$asset->getId
+ extras=>$self->{extras},
+ value=>$asset->getId,
+ id=>$self->{id}
)->toHtml
.WebGUI::Form::text->new(
name=>$self->{name}."_display",
- extras=>'id="'.$self->{name}."_display".'" readonly="1"',
- value=>$asset->get("title")
+ extras=>' readonly="1" ',
+ value=>$asset->get("title"),
+ id=>$self->{id}."_display"
)->toHtml
.WebGUI::Form::button->new(
value=>"...",
- extras=>'onclick="window.open(\''.$asset->getUrl("op=formAssetTree&classLimiter=".$self->{class}."&formId=".$self->{name}).'\',\'assetPicker\',\'toolbar=no, location=no, status=no, directories=no, width=400, height=400\');"'
+ extras=>'onclick="window.open(\''.$asset->getUrl("op=formAssetTree&classLimiter=".$self->{class}."&formId=".$self->{id}).'\',\'assetPicker\',\'toolbar=no, location=no, status=no, directories=no, width=400, height=400\');"'
)->toHtml;
}
diff --git a/lib/WebGUI/Form/button.pm b/lib/WebGUI/Form/button.pm
index db77eddd3..764558968 100644
--- a/lib/WebGUI/Form/button.pm
+++ b/lib/WebGUI/Form/button.pm
@@ -89,7 +89,7 @@ Renders a button.
sub toHtml {
my $self = shift;
my $value = $self->fixQuotes($self->{value});
- return '{extras}.' />';
+ return '{extras}.' />';
}
1;
diff --git a/lib/WebGUI/Form/checkbox.pm b/lib/WebGUI/Form/checkbox.pm
index 87b66c86e..4dcd439f3 100644
--- a/lib/WebGUI/Form/checkbox.pm
+++ b/lib/WebGUI/Form/checkbox.pm
@@ -72,6 +72,18 @@ sub definition {
}
+#-------------------------------------------------------------------
+
+=head2 generateIdParameter ( )
+
+A class method that returns a value to be used as the autogenerated ID for this field instance. Returns undef because this field type can have more than one with the same name, therefore autogenerated ID's aren't terribly useful.
+
+=cut
+
+sub generateIdParameter {
+ return undef
+}
+
#-------------------------------------------------------------------
=head2 getName ()
@@ -97,7 +109,8 @@ sub toHtml {
my $self = shift;
my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->{value})));
my $checkedText = ' checked="checked"' if ($self->{checked});
- return '{extras}.' />';
+ my $idText = ' id="'.$self->{id}.'" ' if ($self->{id});
+ return '{extras}.' />';
}
diff --git a/lib/WebGUI/Form/combo.pm b/lib/WebGUI/Form/combo.pm
index bce7c8a28..ab3be11f6 100644
--- a/lib/WebGUI/Form/combo.pm
+++ b/lib/WebGUI/Form/combo.pm
@@ -83,7 +83,8 @@ sub toHtml {
return $self->SUPER::toHtml
.WebGUI::Form::text->new(
size=>$session{setting}{textBoxSize}-5,
- name=>$self->{name}."_new"
+ name=>$self->{name}."_new",
+ id=>$self->{id}."_new"
)->toHtml;
}
diff --git a/lib/WebGUI/Form/contentType.pm b/lib/WebGUI/Form/contentType.pm
index b3fe50816..a2b611d60 100644
--- a/lib/WebGUI/Form/contentType.pm
+++ b/lib/WebGUI/Form/contentType.pm
@@ -130,6 +130,7 @@ sub toHtml {
}
return WebGUI::Form::selectList->new(
options=>\%types,
+ id=>$self->{id},
name=>$self->{name},
value=>[$self->{value}],
extras=>$self->{extras},
diff --git a/lib/WebGUI/Form/databaseLink.pm b/lib/WebGUI/Form/databaseLink.pm
index be3674d83..e4ce907ee 100644
--- a/lib/WebGUI/Form/databaseLink.pm
+++ b/lib/WebGUI/Form/databaseLink.pm
@@ -120,6 +120,7 @@ Renders a database connection picker control.
sub toHtml {
my $self = shift;
return WebGUI::Form::selectList->new(
+ id=>$self->{id},
name=>$self->{name},
options=>WebGUI::DatabaseLink::getList(),
value=>[$self->{value}],
diff --git a/lib/WebGUI/Form/date.pm b/lib/WebGUI/Form/date.pm
index e45a6fac5..8a0ceaf6e 100644
--- a/lib/WebGUI/Form/date.pm
+++ b/lib/WebGUI/Form/date.pm
@@ -133,11 +133,12 @@ sub toHtml {
name=>$self->{name},
value=>$value,
size=>$self->{size},
- extras=>'id="'.$self->{name}.'Id" '.$self->{extras},
+ extras=>$self->{extras},
+ id=>$self->{id},
maxlength=>$self->{maxlength}
)->toHtml . '