File being over ridden when the Save As name filed is left blank.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

File being over ridden when the Save As name filed is left blank.

aceospade
Hello I have an XForm that is used to keep track of time spent
watching movies. The question is that when the form is loaded from
previous saved data and the name field of the field to be saved is
left blank, the xhtml file is over ridden by the xml file. What I need
is a way for the form not to have a blank save as filed and it would
pop up a modal message saying "Save As Name Required" or something to
that effect. Anyone have any ideas?
Thanks,
Matthew

I have the completed code if this helps any.
Many thanks to John Clark.

_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: File being over ridden when the Save As name filed is left blank.

aceospade
I guess what I am asking is how to make the Save As a "Required" field
and the form will not submit with the field empty. I also wanted to
put a modal message stating what to fill in and what extension to put
at the end of it if the user left the field empty.
Thanks again,
Matthew

_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

RE: File being over ridden when the Save As name filed is left blank.

Clark, John
In reply to this post by aceospade
> What I need
> is a way for the form not to have a blank save as filed and it would
> pop up a modal message saying "Save As Name Required" or something to
> that effect. Anyone have any ideas?

> I have the completed code if this helps any.

You know me, I always like to see the code.  It makes it possible to come up with known-working suggestions.  :)  Essentially what I would try to do is have two different triggers.  They would have two mutually-exclusive XPath references such that the first trigger would only be relevant (and hence, visible) when the filename field was empty, and the second trigger would only be relevant when the filename field was not empty.  When you press the first trigger, you get your error message.  When you press the second trigger, the form is submitted.

Take care,

    John L. Clark

===================================

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News & World Report (2007).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use
only by the individual or entity to which it is addressed
and may contain information that is privileged,
confidential, and exempt from disclosure under applicable
law.  If the reader of this message is not the intended
recipient or the employee or agent responsible for
delivering the message to the intended recipient, you are
hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited.  If
you have received this communication in error,  please
contact the sender immediately and destroy the material in
its entirety, whether electronic or hard copy.  Thank you.


_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: File being over ridden when the Save As name filed is left blank.

Aaron Reed
In reply to this post by aceospade
aceospade wrote:
> I guess what I am asking is how to make the Save As a "Required" field
> and the form will not submit with the field empty. I also wanted to
> put a modal message stating what to fill in and what extension to put
> at the end of it if the user left the field empty.
> Thanks again,
> Matthew
>

use xf:bind with @required="true()".  That will prevent submission if
the bound node is empty.  But you'd need extra logic to know WHY the
submission didn't go through and to put up the message you want.  John's
suggestion is better in that regard.

--Aaron

--Aaron
_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: File being over ridden when the Save As name filed is left blank.

aceospade
Here is what I have so far. Right now if you enter some data and leave
the save as field blank it over rides the xhtml text with the newly
saved xml text. The two trigger idea sounds ideal.
Thanks,
Matthew

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ev="http://www.w3.org/2001/xml-events"
        xmlns:xforms="http://www.w3.org/2002/xforms"
        xmlns:xf="http://www.w3.org/2002/xforms"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xs="http://www.w3.org/2001/XMLSchema">

<head>

<title>Star Wars Movies</title>

<style>
        .date .xf-value {width:70px;}
        .input .xf-value {width:38px;}
        .errorReport:invalid { display: block; color: red; }
  .errorReport:valid { display: none; }
        html {overflow: -moz-scrollbars-vertical;}
</style>

<xf:model id="MovieModel">
        <xf:instance id="main">

                <Time xmlns="">
                        <TimeData>
                                <EntryDate />
                                <StartTime />
                                <StopTime />
                                <BreakTime />
                                <TotalEntryTime />
                                <TotalHours />
                                <Allocated>
                                        <Movie />
                                        <Hours />
                                </Allocated>
                        </TimeData>


                        <TimeData>
                                <EntryDate />
                                <StartTime />
                                <StopTime />
                                <BreakTime />
                                <TotalEntryTime />
                                <TotalHours />
                                <Allocated>
                                        <Movie />
                                        <Hours />
                                </Allocated>
                        </TimeData>
                </Time>

        </xf:instance>

        <xf:instance id="movies" xmlns="">
                <data>
                        <Movie>
                                <Title id="A New Hope" />
                                <Release>1977</Release>
                                <Director>George Lucas</Director>
                                <Episode>IV</Episode>
                                <Characters>Luke, Leia, Han, Chewbacca</Characters>
                        </Movie>
                        <Movie>

                                <Title id="Empire Strikes Back" />
                                <Release>1980</Release>
                                <Director>George Lucas</Director>
                                <Episode>V</Episode>
                                <Characters>Luke, Leia, Darth Vader, Lando</Characters>
                        </Movie>
                        <Movie>
                                <Title id="Return of the Jedi" />
                                <Release>1983</Release>
                                <Director>George Lucas</Director>
                                <Episode>VI</Episode>

                                <Characters>Luke, Boba Fett, Jabba the hutt</Characters>
                        </Movie>
                        <Movie>
                                <Title id="The Phantom Menace" />
                                <Release>1999</Release>
                                <Director>George Lucas</Director>
                                <Episode>I</Episode>
                                <Characters>Anakin, Qui-Gonn, Obi-Won</Characters>
                        </Movie>
                        <Movie>

                                <Title id="Attack of the Clones" />
                                <Release>2002</Release>
                                <Director>George Lucas</Director>
                                <Episode>II</Episode>
                                <Characters>Anakin, Obi-Won, Count Dooku</Characters>
                        </Movie>
                        <Movie>
                                <Title id="Revenge of the Sith" />
                                <Release>2005</Release>
                                <Director>George Lucas</Director>
                                <Episode>III</Episode>

                                <Characters>Anakin, Obi-Won, Mace Windu, Emperor Palpatine</
Characters>
                        </Movie>
                </data>
        </xf:instance>

        <xf:instance id="selected-movie" xmlns="">
                <movie-id xmlns="">A New Hope</movie-id>
        </xf:instance>

        <xf:instance id="selected" xmlns="">

                <movie-id xmlns="">Empire Strikes Back</movie-id>
        </xf:instance>

        <xf:instance id="save-as" xmlns="">
           <save-as>
               <File xsi:type="xs:anyURI">.xml</File>
           </save-as>
        </xf:instance>

        <xf:instance id="load-from" xmlns="">

           <load-form>
               <File xsi:type="xs:anyURI"></File>
           </load-form>
        </xf:instance>

        <xf:bind nodeset="instance('movies')">
                <xf:bind nodeset="/data/Movie/Title" required="true( )" id="title" /
>
                <xf:bind nodeset="/data/Movie/Release" required="true( )"
id="release" />
                <xf:bind nodeset="/data/Movie/Director" required="true( )"
                        id="director" />

                <xf:bind nodeset="/data/Movie/Episode" required="true( )"
id="episode" />
                <xf:bind nodeset="/data/Movie/Characters" required="true( )"
                        id="characters" />
        </xf:bind>

    <xf:bind nodeset="/Time/TimeData[position() &lt; last()]/
EntryDate"
    required="true()" type="xsd:date" />

                <xf:bind nodeset="TimeData/TotalEntryTime"
                        calculate="../StopTime - ../StartTime - ../BreakTime" />

                <xf:bind nodeset="/Time/TimeData/TotalHours"
                        calculate="sum(../Allocated[string(Movie)]/Hours)" />

                <xf:bind nodeset="/Time/TimeData[position() &lt;last()]/
TotalEntryTime"
                  constraint=". = ../TotalHours" />

          <xf:action ev:event="xforms-ready">
          <xf:setfocus control="movieEntry" />

      </xf:action>

      <xf:action ev:event="xforms-ready">
      <xf:rebuild model="MovieModel" />
  </xf:action>

        <xf:submission id="submit" ref="/Time" replace="none" method="put" >
  <xf:resource value="instance('save-as')/File"/>
        </xf:submission>

        <xf:submission id="load" replace="instance" instance="main"
method="get" validate="false">
           <xf:resource value="instance('load-from')/File"/>
        </xf:submission>

</xf:model>

<link rel="icon" type="image/ico" href="favicon3.ico" />

</head>

<body>
<center><img src="StarWars_logo.jpg" /></center>

<xf:select1 ref="instance('selected-movie')">
        <xf:label>
                <b>Film: </b>
        </xf:label>

        <xf:itemset nodeset="instance('movies')/Movie/Title/@id">
                <xf:label ref="." />
                <xf:value ref="." />
        </xf:itemset>
</xf:select1>


<xf:group
        ref="instance('movies')/Movie[Title/@id = instance('selected-
movie')]">
        <dl>
                <dt><b>Title: </b> <xf:output ref="Title/@id" /></dt>

                <dt><b>Release: </b> <xf:output ref="Release" /></dt>
                <dt><b>Director: </b> <xf:output ref="Director" /></dt>
                <dt><b>Episode: </b> <xf:output ref="Episode" /></dt>
                <dt><b>Characters: </b> <xf:output ref="Characters" /></dt>
        </dl>

</xf:group>

        <xf:trigger>
                <xf:label>
                        <b>Add an entry?</b>
                </xf:label>
                <xf:action ev:event="DOMActivate">
                        <xf:insert nodeset="TimeData" at="index('TimeData-repeat')"
position="after" />
                        <xf:setfocus control="TimeData-repeat" />

                        <xf:rebuild nodeset="TimeData" at="index('TimeData-repeat')" />
                </xf:action>
        </xf:trigger>

        <xf:trigger>
                <xf:action ev:event="DOMActivate">
                        <xf:label><b>Remove current entry?</b></xf:label>
                        <xf:delete nodeset="TimeData[last()&gt;1]" at="index('TimeData-
repeat')" />
                        <xf:insert nodeset="TimeData[last()=1]" at="index('TimeData-
repeat')" position="before" />

                </xf:action>
        </xf:trigger>
        <br />
        <br />
<xf:repeat nodeset="TimeData[position()!=last()]" id="TimeData-
repeat">
        <xf:label>Date: <xf:input ref="EntryDate" class="date" />&nbsp;</
xf:label>
        <xf:label>Begin: <xf:input ref="StartTime" class="input" /></
xf:label>
        <xf:label>End: <xf:input ref="StopTime" class="input" /></xf:label>

        <xf:label>Break: <xf:input ref="BreakTime" class="input" /></
xf:label>
        <xf:label>Total: <xf:input ref="TotalEntryTime" class="input" /></
xf:label>

        <br />
        <br />
        <xf:select1 ref="instance('selected')">
                <xf:label>
                        <b>Film: </b>

                </xf:label>
                <xf:itemset nodeset="instance('movies')/Movie/Title/@id">
                        <xf:label ref="." />
                        <xf:value ref="." />
                </xf:itemset>
        </xf:select1>
&nbsp; &nbsp;
        <xf:trigger>
                <xf:label>Add Movie</xf:label>

                <xf:action ev:event="DOMActivate">
                        <xf:insert nodeset="Allocated[position()=index('newmovies-list')]"
                                at="index('newmovies-list')" />
                        <xf:setvalue ref="Allocated[index('newmovies-list')]/Movie"
                                value="instance('movies')/Movie[Title/@id = instance('selected')]/
Title/@id" />
                        <xf:setfocus control="movieEntry" />
            <xf:rebuild/>
            <xf:refresh/>
                </xf:action>
        </xf:trigger>

        <xf:trigger>
                <xf:label>Delete Movie</xf:label>
                <xf:action ev:event="DOMActivate">
                        <xf:delete nodeset="Allocated[position()!=last()]"
at="index('newmovies-list')" />
                </xf:action>
        </xf:trigger>

        <xf:trigger>
                <xf:label>Recalculate</xf:label>

                <xf:action ev:event="DOMActivate">
                        <xf:recalculate />
                        <xf:refresh />
                </xf:action>
        </xf:trigger>

        <br />
        <br />
<table>
<tr>
<td>

        <xf:repeat id="newmovies-list" nodeset="Allocated">
                <xf:label>Movie: <xf:input ref="Movie" id="movieEntry" />
                </xf:label>
                <xf:label>Hours: <xf:input ref="Hours" />
                </xf:label>
        </xf:repeat></td>
        <td><xf:label>Total: <xf:input ref="TotalHours" class="input" /></
xf:label></td>

        <td><xf:group ref="TotalEntryTime" class="errorReport">
    <b>Your times don't add up!</b>
  </xf:group></td>
  </tr>
  </table>
        <br />
</xf:repeat>

<xf:input ref="instance('save-as')/File" required="true"
name="name_id" needed="name_id != ''">
  <xf:label>Save location: </xf:label>

</xf:input>

<xf:submit submission="submit">
        <xf:label> Save </xf:label>
</xf:submit>

<xf:upload ref="instance('load-from')/File">
  <xf:label>Load from: </xf:label>
</xf:upload>

<xf:submit submission="load">
        <xf:label>Load</xf:label>

</xf:submit>



</body>
</html>

_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms