Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation for multiple sections doesn't work #8

Closed
patrickyan opened this issue Jul 17, 2013 · 5 comments
Closed

Validation for multiple sections doesn't work #8

patrickyan opened this issue Jul 17, 2013 · 5 comments

Comments

@patrickyan
Copy link

I'm not sure what the exact problem is, but here's what's going on:

I have something like this

<!-- Interpret the values from event. It can be customized. See the implementation -->
<xsl:variable name="formi">
    <xsl:call-template name="sform:formi">
        <xsl:with-param name="section" select="$section"/>
    </xsl:call-template>
</xsl:variable>
<xsl:variable name="formi-images">
    <xsl:call-template name="sform:formi">
        <xsl:with-param name="section" select="'images'"/>
    </xsl:call-template>
</xsl:variable>

<!-- Render this interpretation as pretty HTML. It can be customized. See the implementation -->
<xsl:call-template name="sform:validation-render">
    <xsl:with-param name="interpretation" select="$formi"/>
</xsl:call-template>
<xsl:call-template name="sform:validation-render">
    <xsl:with-param name="interpretation" select="$formi-images"/>
</xsl:call-template>

I basically have posts with images. The upload field in the images field has a validation to only allow image files. If I try to upload a PDF, I get two empty success divs:

          <div class="validation success">
            <div class="">
              <p class="item-"></p>
            </div>
          </div>
          <div class="validation success">
            <div class="">
              <p class="item-"></p>
            </div>
          </div>

But the event XML is showing this:

    <coolsection>
        <entry position="0">
            <post-values>
                stuff
            </post-values>
            <rep-post-values>
                stuff
            </rep-post-values>
            <entry action="edit" />
            <fields />
            <filters />
        </entry>
    </coolsection>

In the images section:

    <images>
        <entry position="0">
            <post-values>
                <image>
                    <name>kinvolvedinvite.jpg</name>
                    <type>image/jpeg</type>
                    <tmp-name>/Applications/MAMP/tmp/php/phpJyDZSc</tmp-name>
                    <size>255072</size>
                </image>
            </post-values>
            <rep-post-values>
                <image>
                    <name>kinvolvedinvite.jpg</name>
                    <type>image/jpeg</type>
                    <tmp-name>/Applications/MAMP/tmp/php/phpJyDZSc</tmp-name>
                    <size>255072</size>
                </image>
            </rep-post-values>
            <entry action="create" />
            <fields />
            <filters />
        </entry>
        <entry position="1">
            <post-values>
                <image>
                    <name>Kinvolved invite.pdf</name>
                    <type>application/pdf</type>
                    <tmp-name>/Applications/MAMP/tmp/php/phpKMXK3H</tmp-name>
                    <size>172379</size>
                </image>
            </post-values>
            <rep-post-values>
                <image>
                    <name>Kinvolved invite.pdf</name>
                    <type>application/pdf</type>
                    <tmp-name>/Applications/MAMP/tmp/php/phpKMXK3H</tmp-name>
                    <size>172379</size>
                </image>
            </rep-post-values>
            <entry action="create" result="error">
                <message>Entry encountered errors when saving.</message>
            </entry>
            <fields>
                <image label="Image" type="invalid" message="File chosen in ‘Image’ does not match allowable file types for that field." code="220" />
            </fields>
            <filters />
        </entry>
    </images>

Problems:

  1. Can the validation messages be consolidated into 1 div instead of having 2 divs?
  2. If the entry is edited successfully, it should say so.
  3. Error messages are not showing.
@vlad-ghita
Copy link
Owner

Perhaps it's related to #7. I'll re-re-fix it and please check again this one.

@vlad-ghita
Copy link
Owner

Ok, now I understood what you're saying. I pushed some local XSLT fixes to version 2.3.2.

  1. Can the validation messages be consolidated into 1 div instead of having 2 divs?

The idea behind sform:formi is to gather data about the status of one entry. It accepts a position parameter which conveniently defaults to first entry. In general, all forms target only one entry in a section. That's why you don't need to set it. But in this case you submit data to multiple entries in one section so you must set this parameter as well. Hands on, Image#2 in your case will incorrectly receive the interpretation from Image#1. The correct way is to call the interpretation for every image like this:

<xsl:variable name="formi-image">
    <xsl:call-template name="sform:formi">
        <xsl:with-param name="section" select="'images'"/>
        <!-- I assume you used the position() function here or something similar -->
        <xsl:with-param name="position" select="position()"/>
    </xsl:call-template>
</xsl:variable>

The idea behind sform:validation-render is to pretty render information about only one entry.

If you want to display a consolidated message for all entries, gather all interpretations from all entries and manually write some code to display appropriate message.

  1. If the entry is edited successfully, it should say so.
  2. Error messages are not showing.

These are the processing stages. All entries go through each stage simultaneously:

  1. Prepare incomming data
  2. Check permissions
  3. Delete entries
  4. Check field data
  5. Set field data
  6. Replace variables
  7. Persist entries to database

In your case, Entry#1 passed Stage#4 but Entry#2 didn't.

The success message is applied to an Entry only if it passes Stage#7.

An appropriate error message is applied to an Entry whenever it fails at one stage.

If any entry fails at any stage, processing is stopped after that stage is completed and current status is returned.

@patrickyan
Copy link
Author

Thanks for the clarification. The fields for the multiple entries I'm creating are actually being inserted via javascript, so if sform:formi needs to be called for each entry, I can't use it. Even though sform:validation-render only renders messages for one entry, shouldn't it be able to render all messages for all entries by just reiterating over the returned event xml?

I'll check out the updated utilities to see if it addresses the blank divs issue!

@vlad-ghita
Copy link
Owner

I'll check out the updated utilities to see if it addresses the blank divs issue!

It won't :)

Even though sform:validation-render only renders messages for one entry, shouldn't it be able to render all messages for all entries by just reiterating over the returned event xml?

No. It's soul job is to render one entry.

If you need to render all entries in given wrapper or something, then ... do it.

Of course there is room for improvement: another sform:validation-render-all template or similar that would do exactly what you're saying, but it's a niche case at the moment. With Symphony Next these ideas will be thought over for good.

@patrickyan
Copy link
Author

Alright thanks for your thoughts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants