DateTime Fields

rss

Posted by SpongeBen SquareJaw - Nov 24 ’14 at 04:39

Is there a way to get the minutes in the date time fields to enter by actual minute, not just increments of 5.

I would even take entering value through java or jquery on forms.

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 9 years 8 months 7 days
    #1 by Dmitry Kozlov Nov 25 ’14 at 04:53

    Hello,

    Yes, you can replace the default date and time control with simple input field following way:

    1. Remove Date&Time field from your Edit form

    2. Put HTML-control

    3. Set CDATA property to False

    4. Set Content to:

    <asp:TextBox ID="DateTimeTextBox" runat="server" Text="{ddwrt:FormatDateTime(string(@DateTime), 1033, 'g')}" __designer:bind="{ddwrt:DataBind('u','DateTimeTextBox','Text','Load','ID',ddwrt:EscapeDelims(string(@ID)),'@DateTime')}" />

    5. Replace the highlighted text with the internal name of your date & time field.

    6. Save the form.

    PS: HTML-content for the New form:

    <asp:TextBox ID="DateTimeTextBox" runat="server" Text="{ddwrt:FormatDateTime(string(@DateTime), 1033, 'g')}" __designer:bind="{ddwrt:DataBind('i','DateTimeTextBox','Text','Load','ID',ddwrt:EscapeDelims(string(@ID)),'@DateTime')}" />

  • SpongeBen SquareJaw
    Member
    Member for: 8 years 7 months 8 days
    #2 by SpongeBen SquareJaw Nov 25 ’14 at 11:07

    [#1]: Thanks this works but it errors when I have no value. This field is set to allow blank values. I'm guessing it is a format error since it is formatting a blank value.

  • SpongeBen SquareJaw
    Member
    Member for: 8 years 7 months 8 days
    #3 by SpongeBen SquareJaw Nov 26 ’14 at 09:54

    [#1]: Is there a way for this to except empty or Null values?

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 9 years 8 months 7 days
    #4 by Dmitry Kozlov Nov 27 ’14 at 09:50

    [#3]: You can assign a default value to the textbox if it's empty right before the submission with the help of JavaScript. First, assign a CSS class to your textbox:

    <asp:TextBox ID="DateTimeTextBox" runat="server" CssClass="date-time-textbox" Text="{ddwrt:FormatDateTime(string(@DateTime), 1033, 'g')}" __designer:bind="{ddwrt:DataBind('u','DateTimeTextBox','Text','Load','ID',ddwrt:EscapeDelims(string(@ID)),'@DateTime')}" />

    Next, put the following code into JS-editor:

    fd.onsubmit(function() {
    	if (!$('.date-time-textbox').val().trim()) {
    		$('.date-time-textbox').val('01/01/2014 12:00 AM');
    	}
    	return true;
    }); 
    
  • SpongeBen SquareJaw
    Member
    Member for: 8 years 7 months 8 days
    #5 by SpongeBen SquareJaw Dec 3 ’14 at 03:34

    [#4]: This will not work because we leave this date blank until a process is complete. So it has to be able to be blank from initial insert and updates. Putting in a date is not going to work for my needs.

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 9 years 8 months 7 days
    #6 by Dmitry Kozlov Dec 4 ’14 at 05:32

    [#5]: So you can create a separate form containing the date and time field and display it only when the process is completed with the help of groups functionality. Other forms will not contain this field.

    Or you can clear the default value of the date and time field with the help of JavaScript on initial form loading and set its value back right before the submission.

  • Dan_C
    Member
    Member for: 8 years 6 months 2 days
    #7 by Dan_C Dec 4 ’14 at 03:09

    This is a problem for me as well.

    I'm trying to update various DateTime fields to record when a user presses a button.  I want to record the exact time... not five minute increments.  I also don't want a default time either because I want a time there only if the user presses the button.

    Why is there a five minute increment limitation?  Is there not a way in SP Forms to update a DateTime field with the exact time OnClick?

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 9 years 8 months 7 days
    #8 by Dmitry Kozlov Dec 4 ’14 at 03:20

    [#7]: This is SharePoint limitation. Forms Designer just rearranges out-of-the-box controls. I've suggested an option that is quite easy to implement. But you can still develop a custom field and add it to your list. Forms Designer supports custom fields.

    Our support team can help you with this task, just send the detailed requirements to [email protected] and they will estimate them.

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 9 years 8 months 7 days
    #9 by Dmitry Kozlov Dec 4 ’14 at 03:23

    [#8]: Also you can store your date and time in a plain text field especially if you set it automatically via JavaScript.

  • Dan_C
    Member
    Member for: 8 years 6 months 2 days
    #10 by Dan_C Dec 4 ’14 at 03:43

    [#9]: I was just wondering about that.  I'm new to SharePoint and to SP Forms.  If I store the value in a text column the draw back would be I'd have to convert the text back to a datetime variable to use it programatically in the future, right?

    Something like talked about here:

    http://forums.asp.net/t/1861281.aspx?How+To+convert+string+into+datetime+in+javascript

    Not too bad, but probably has other drawbacks too...

Displaying 1 to 10 of 14 messages
Previous12