6 Replies Latest reply on Oct 24, 2012 8:46 AM by Gary Miller

    Error implementing DateTimePicker

      I'm new to RhoStudio and trying to find my way by reading docs and developing a simple app. 

      My current problem is trying to implement the Native Control DateTimePicker, using as my source

      the weekly Webinar video "Using Native Controls" by Brian Moores.  Using the iphone simulator

      the app loads and everything appears normal until I press the Edit button to show the DateTimePicker,

      then I get an error UNDEFINED on the simulator screen.  I think the error is telling me that my

      method "choose", i.e. DateTimePicker.choose( url_for( :action => :datetime_callback), $title, Time.new, $flag.to_i, Marshal.dump($flag))

      is not defined, but if that's it I have no clue why. 

       

      I have attached some screen shots and the portion of the book_inventory_controller.rb file and can provide more info if needed.

       

      Any ideas would be appreciated.

       

      Thanks,

       

      Gary

       

      .......................  book_inventory_controller.rb file ..............................

      require 'rho/rhocontroller'

      require 'helpers/browser_helper'

       

      class BookInventoryController < Rho::RhoController

        include BrowserHelper

       

        #Date Time Picker

          $saved = nil

          $choosed = {}

           

         

          def choose

            puts "Choose Date/Time"

           

            $flag  = @params['flag']

            $title = @params['title']

             

            if $flag == '0' or $flag == '1' or $flag == '2'

              $saved = nil

              DateTimePicker.choose( url_for( :action => :datetime_callback), $title, Time.new, $flag.to_i, Marshal.dump($flag))

            end

            ""

          end 

          

          def save

            $saved = 1

            redirect :action => :index

          end

         

          def datetime_callback

            puts "datetime_callback"

            $status = @params['status']

              if $status == 'ok'

                $dt = Time.at( @params ['result'].to_i)

                  $flag = Marshal.load(@params['opaque'])

                    format = case $flag

                    when "0" then '%F %T'

                    when "1" then '%F'

                    when "2" then '%T'

                 else '%F %T'

                    end

              $choosed[$flag] = $dt.strftime( format )

              end

             

             webview.navigate( url_for( :action => :index))

             ""

          end

      ..................................................................................

        • Re: Error implementing DateTimePicker
          Peter Arcuri

          Gary, could your issue be related to the data bug? See details at https://developer.motorolasolutions.com/message/5161#5161

            • Re: Error implementing DateTimePicker

              Peter,

               

              Thanks for the reply.  It's possible this is related,  but doesn't seem to fit entirely.  I'm not using RhoElement and I'm running Mac OS also I'm not getting a wrong date but rather the DateTimePicker isn't even appearing.

               

              Do you see anything with my code that could be causing a problem?

               

              Thanks again,

               

              Gary

            • Re: Error implementing DateTimePicker
              Derek Warren

              Can you please enclosed the code from your html/erb page?

                • Re: Error implementing DateTimePicker

                  Hi Derek,

                   

                  Here you go - thanks!  It's the edit.erb file.

                   

                   

                  div data-role="page">

                   

                    <div data-role="header" data-position="inline">

                      <h1>Edit <%= @bookinventory.Title %></h1>

                      <a href="<%= url_for :action => :show, :id => @bookinventory.object %>" class="ui-btn-left" data-icon="back" data-direction="reverse">

                        Cancel

                      </a>

                      <a href="<%= url_for :action => :delete, :id => @bookinventory.object %>" class="ui-btn-right" data-icon="delete" data-direction="reverse">

                        Delete

                      </a>

                    </div>

                   

                    <div data-role="content">

                      <form method="POST" action="<%= url_for :action => :update %>">

                        <input type="hidden" name="id" value="<%= @bookinventory.object %>"/>

                       

                            <div data-role="fieldcontain">

                              <label for="bookinventory[Title]" class="fieldLabel">Title</label>

                              <input type="text" id="bookinventory[Title]" name="bookinventory[Title]" value="<%= @bookinventory.Title %>" <%= placeholder( "Title" ) %> />

                            </div>

                       

                            <div data-role="fieldcontain">

                              <label for="bookinventory[Author]" class="fieldLabel">Author</label>

                              <input type="text" id="bookinventory[Author]" name="bookinventory[Author]" value="<%= @bookinventory.Author %>" <%= placeholder( "Author" ) %> />

                            </div>

                       

                            <div data-role="fieldcontain">

                              <label for="bookinventory[OwnershipCode]" class="fieldLabel">Ownershipcode</label>

                              <input type="text" id="bookinventory[OwnershipCode]" name="bookinventory[OwnershipCode]" value="<%= @bookinventory.OwnershipCode %>" <%= placeholder( "Ownershipcode" ) %> />

                            </div>

                       

                            <div data-role="fieldcontain">

                              <label for="bookinventory[OwnershipName]" class="fieldLabel">Ownershipname</label>

                              <input type="text" id="bookinventory[OwnershipName]" name="bookinventory[OwnershipName]" value="<%= @bookinventory.OwnershipName %>" <%= placeholder( "Ownershipname" ) %> />

                            </div>

                       

                            <div data-role="fieldcontain">

                              <label for="bookinventory[ObtainedFrom]" class="fieldLabel">Obtainedfrom</label>

                              <input type="text" id="bookinventory[ObtainedFrom]" name="bookinventory[ObtainedFrom]" value="<%= @bookinventory.ObtainedFrom %>" <%= placeholder( "Obtainedfrom" ) %> />

                            </div>

                           

                    

                            <div data-role="fieldcontain">

                              <label for="bookinventory[DateRecd]" class="fieldLabel">Daterecd</label>

                              <input type="text" id="bookinventory[DateRecd]" name="bookinventory[DateRecd]" value="<%= @bookinventory.DateRecd %>" <%= placeholder( "Daterecd" ) %> />

                          

                                      <p>Test Date/Time Pickers</p>

                                      <form action = "DateTime/save">

                                        <b>Date and Time:</b><br/>

                                          <input type ="text" name="date0" readonly value="<%= $choosed['0'] %>"></input>

                                          <%= link_to "Edit", { :action => "choose", :query => {$flag => '0', :$title => 'Choose Date & Time'} } %><br/>

                                        <b>Date Only: </b><br/>

                                          <input type = "text" name = "date1" readonly value = "<%= $choosed['1'] %>"></input>

                                          <%= link_to "Edit", { :action => "choose", :query => {$flag => '1', :$title => 'Choose Date'} } %><br/>

                                        <b>Date and Time: </b><br/>

                                          <input type = "text" name = "date2" readonly value = "<%= $choosed['2'] %>"></input>

                                          <%= link_to "Edit", { :action => "choose", :query => {$flag => '2', :$title => 'Choose Time'} } %><br/>

                                      <input type = "submit" value="save"></input>

                                      </form>

                                      <br/>

                                      <% if not $saved.nil? %>

                                        chosen date/time values: <br/>

                                      <% $choosed.each do |k,v| %>

                                        <b> Format (<%=k%>: <%= v %></b><br/>)

                                      <% end %>

                                <% end %>

                              </div>

                       

                        <input type="submit" value="Update"/>

                      </form>

                    </div>

                   

                  </div>

                    • Re: Error implementing DateTimePicker
                      Derek Warren

                      Take a look at how you are passing the parameters to the choose method in controller. Your choose method is looking for a 'flag' and 'title' but you are not using the parameters. If you remove the if statement in your choose method the picker will appear because the $flag=@params['flag'] is nil. You should pass the parameters from the ERB page as symbols ( :flag and :title) not variables this should fix the issue.

                       

                      Overall, change $flag and :$title in your ERB page to :flag and :title.

                        • Re: Error implementing DateTimePicker

                          Derek,

                           

                          Thanks much, that worked!!!  I'm now getting the DateTimePicker displayed and I can pick Date, Date/Time or Time depending which one I have selected on the Edit screen  It still displays "undefined" at the top of the screen where the DateTimePicker is displayed and it does not automatically go back to the edit screen once I select a Date and click OK, which I thought was suppose to do, but this is real progress. See Screen image.

                           

                          Thanks again,

                           

                          Gary

                          Choose Date & Time-Undefind.jpg