diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt
index 6b21eb728..a7ed982a9 100644
--- a/docs/changelog/7.x.x.txt
+++ b/docs/changelog/7.x.x.txt
@@ -13,6 +13,7 @@
- fixed #12007: Hardcoded js in cart view ( Martin Kamerbeek / Oqapi )
- fixed #12010: Related URLs are not copied for events created through recurrence
- fixed #12012: WebGUI Account system does not present login to visitors for proper redirect
+ - fixed #12015: Thingy: Custom 'File' form fields get deleted upon save
7.10.6
- fixed #11974: Toolbar icons unclickable in Webkit using HTML5
diff --git a/lib/WebGUI/Asset/Wobject/Thingy.pm b/lib/WebGUI/Asset/Wobject/Thingy.pm
index e6737e080..8e90bb9a6 100644
--- a/lib/WebGUI/Asset/Wobject/Thingy.pm
+++ b/lib/WebGUI/Asset/Wobject/Thingy.pm
@@ -454,7 +454,7 @@ sub copyThingData {
my @storage_field_ids = ();
##Check to see if any of them are File or Image
foreach my $field (@{ $fields }) {
- if ($field->{fieldType} eq 'File' or $field->{fieldType} eq 'Image') {
+ if ($self->field_isa($field->{fieldType}, 'WebGUI::Form::File')) {
push @storage_field_ids, $field->{fieldId};
}
}
@@ -512,7 +512,7 @@ sub deleteThingData {
my @storage_field_ids = ();
##Check to see if any of them are File or Image
foreach my $field (@{ $fields }) {
- if ($field->{fieldType} eq 'File' or $field->{fieldType} eq 'Image') {
+ if ($self->field_isa($field->{fieldType}, 'WebGUI::Form::File')) {
push @storage_field_ids, $field->{fieldId};
}
}
@@ -610,7 +610,7 @@ sub editThingDataSave {
$fieldType = "" if ($fieldType =~ m/^otherThing/x);
# Modify the defaultValue for certain field types. For most types we want to use
# the default in the database, for these we want the last known value for this thingData
- if ( $fieldType eq "File" || $fieldType eq "Image" ) {
+ if ($self->field_isa($fieldType, 'WebGUI::Form::File')) {
$field->{ defaultValue } = $thingData{ "field_" . $field->{ fieldId } };
}
$fieldValue = $thingData->{$fieldName} || $session->form->process($fieldName,$fieldType,$field->{defaultValue},$field);
@@ -674,6 +674,32 @@ sub exportAssetData {
#-------------------------------------------------------------------
+=head2 field_isa ( $fieldType, $isa )
+
+Builds a form field and does an isa check on it.
+
+=head2 $fieldType
+
+This is the type of a field to build. It will have 'WebGUI::Form' prepended to it to form
+a complete classname.
+
+=head2 $isa
+
+This is the class name to check against.
+
+=cut
+
+sub field_isa {
+ my $self = shift;
+ my $session = $self->session;
+ my $fieldType = shift;
+ my $isa = shift;
+ my $control = eval { WebGUI::Pluggable::instanciate("WebGUI::Form::".$fieldType, "new", [ $session, () ]) };
+ return ($control && $control->isa($isa));
+}
+
+#-------------------------------------------------------------------
+
=head2 _getDbDataType ( fieldType )
returns the database data type for a field based on the fieldType.
@@ -1853,12 +1879,12 @@ sub www_editThing {
$fields = $self->session->db->read('select * from Thingy_fields where assetId = '.$self->session->db->quote($self->get("assetId")).' and thingId = '.$self->session->db->quote($thingId).' order by sequenceNumber');
while (my $field = $fields->hashRef) {
my $formElement;
- if ($field->{fieldType} eq "File"){
- $formElement = "";
- }
- if ($field->{fieldType} eq "Image"){
+ if ($self->field_isa($field->{fieldType}, 'WebGUI::Form::Image')) {
$formElement = "";
}
+ elsif ($self->field_isa($field->{fieldType}, 'WebGUI::Form::File')) {
+ $formElement = "";
+ }
else{
$formElement = $self->getFormElement($field);
}
@@ -2301,12 +2327,12 @@ sub www_editFieldSave {
$newFieldId = $self->setCollateral("Thingy_fields","fieldId",\%properties,1,1,"thingId",$thingId);
}
- if ($properties{fieldType} eq "File"){
- $formElement = "";
- }
- elsif ($properties{fieldType} eq "Image"){
+ if ($self->field_isa($properties{fieldType}, 'WebGUI::Form::Image')) {
$formElement = "";
}
+ elsif ($self->field_isa($properties{fieldType}, 'WebGUI::Form::File')) {
+ $formElement = "";
+ }
else{
$formElement = $self->getFormElement(\%properties);
}
diff --git a/t/Asset/Wobject/Thingy.t b/t/Asset/Wobject/Thingy.t
index 6bbfd9f0c..5eca465de 100644
--- a/t/Asset/Wobject/Thingy.t
+++ b/t/Asset/Wobject/Thingy.t
@@ -436,7 +436,6 @@ $session->request->setup_body({
$session->user({userId => '3'});
$session->http->setStatus(200);
my $json = $thingy->www_editThingDataSaveViaAjax();
-diag "json: ".$json;
is $json, '{}', 'www_editThingDataSaveViaAjax: Empty JSON hash';
is $session->http->getStatus, 200, '... http status=200';