Quantcast

Odd behaviour (bug?) creating a topic with a form

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Odd behaviour (bug?) creating a topic with a form

BramVanOosterhout
Dear Mailing list,

I am using Foswiki 2.1.2

I am creating a topic with a dataform, using:
http://192.168.1.170/devwiki/bin/edit/Sandbox/BugAUTOINC000000?t=1478475991;formtemplate=Applications/BugApp.BugForm

The BugForm includes:
| *Name*       | *Type* | *Size* | *Values* | *Tooltip message* | *Attributes*
| *Default:* |
| TopicType    | label | 1 | BugTopic, WikiTopic | topic type  | | |

I found that the TopicType was never inserted in the topic created. I expected:
TopicType BugTopic, WikiTopic
And got:
TopicType

After some work tracing and debugging, I find I can fix this by changing
Foswiki/UI/Form.pm lines:

    529             unless ( defined($value) ) {
    530
    531                 my $dv = $fieldDef->getDefaultValue($value);
    532                 if ( defined($dv) ) {
    533                     $dv    = $topicObject->expandMacros($dv);
    534                     $value = Foswiki::expandStandardEscapes($dv);    #
Item2837
    535                 }
    536             }


to:
    529             unless ( defined($value) ) {
    530
         ############## my $dv = $fieldDef->getDefaultValue($value);
    531                 my $dv = $fieldDef->{value};
    532                 if ( defined($dv) ) {
    533                     $dv    = $topicObject->expandMacros($dv);
    534                     $value = Foswiki::expandStandardEscapes($dv);    #
Item2837
    535                 }
    536             }

I am not sure how getDefaultValue is expected to achieve its objective by
passing it a undefined value, nor am I sure that this fix has no side effects.

Can you shed any light on this?
Thanks in advance.

--
Bram van Oosterhout


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Foswiki-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/foswiki-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Odd behaviour (bug?) creating a topic with a form

BramVanOosterhout
Hi All,

I have slept on this and discovered that $fieldDef->getDefaultValue($value);
returns '' because the fieldDef structure contains:
          bless( {
                   'attributes' => '',
    ===>           'default' => '',
                   'definingTopic' => '',
                   'description' => 'topic type',
                   'name' => 'TopicType',
                   'session' => 'Foswiki=HASH(0x942bd74)',
                   'size' => '1',
                   'title' => 'TopicType',
                   'topic' => 'BugForm',
                   'type' => 'label',
                   'validModifiers' => 'ARRAY(0xa6f4aac)',
    ===>           'value' => 'BugTopic, WikiTopic',
                   'web' => 'Applications/BugApp'
                 }, 'Foswiki::Form::Label' ),

And the logic in getDefaultValue is:

Foswiki/Form/FieldDefinition.pm line:
    180 sub getDefaultValue {
    181     my $this = shift;
    182
    183     my $value =
    184       ( exists( $this->{default} ) ? $this->{default} : $this->{value} );
    185     $value = '' unless defined $value;    # allow 0 values
    186
    187     return $value;
    188 }

So $this->{default} exists AND is empty, so the returned default is empty.

Where would the default be set. Or should the logic be:

    183     my $value =
    184       ( exists( $this->{value} ) ? $this->{value} : $this->{default} );

Any advice appreciated




--
Bram van Oosterhout


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Foswiki-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/foswiki-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Odd behaviour (bug?) creating a topic with a form

Chris Hoefler
Either take out the "Default" column in your form definition or put the "BugTopic, WikiTopic" value in it. The "Default" column overrides the "Values" column. You can also specify "TopicType='BugTopic, WikiTopic" in your request as a parameter to set the form field value. I think you must use a POST to do this though <input type="hidden" name="TopicType" value="BugTopic, WikiTopic"  />). It is very handy when you need to create UIs using html forms.

On Mon, Nov 7, 2016 at 8:17 AM, Bram van Oosterhout <[hidden email]> wrote:
Hi All,

I have slept on this and discovered that $fieldDef->getDefaultValue($value);
returns '' because the fieldDef structure contains:
          bless( {
                   'attributes' => '',
    ===>           'default' => '',
                   'definingTopic' => '',
                   'description' => 'topic type',
                   'name' => 'TopicType',
                   'session' => 'Foswiki=HASH(0x942bd74)',
                   'size' => '1',
                   'title' => 'TopicType',
                   'topic' => 'BugForm',
                   'type' => 'label',
                   'validModifiers' => 'ARRAY(0xa6f4aac)',
    ===>           'value' => 'BugTopic, WikiTopic',
                   'web' => 'Applications/BugApp'
                 }, 'Foswiki::Form::Label' ),

And the logic in getDefaultValue is:

Foswiki/Form/FieldDefinition.pm line:
    180 sub getDefaultValue {
    181     my $this = shift;
    182
    183     my $value =
    184       ( exists( $this->{default} ) ? $this->{default} : $this->{value} );
    185     $value = '' unless defined $value;    # allow 0 values
    186
    187     return $value;
    188 }

So $this->{default} exists AND is empty, so the returned default is empty.

Where would the default be set. Or should the logic be:

    183     my $value =
    184       ( exists( $this->{value} ) ? $this->{value} : $this->{default} );

Any advice appreciated




--
Bram van Oosterhout


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Foswiki-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/foswiki-discuss


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Foswiki-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/foswiki-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Odd behaviour (bug?) creating a topic with a

BramVanOosterhout
Thanks Chris,
I read the manual on Data Forms again. And lo!


"Default" is used in preference to "Values".

For text, there is no difference. But if you use the Default collumn, you
must set Default to seed a value.

For checkboxes, radio buttons and dropdown lists I can create the topic
showing option A,B,C (in Default). And maintain with options A, B, C, D, E ,F
(in Values).

Duh...

And I needed the debugger, the forum and someone smart to tell me that :-)

Thank you!

--
 Bram van Oosterhout


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Foswiki-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/foswiki-discuss
Loading...