Search code examples
2sxc

Date always last entry


I have an app that ask 2 things 1. How do you feel? 2. what date is it?

The answer to question 1 is shown correctly in the list but the date is always the value of the last entry.

To display the date, I have in the template:

@Content.Datum.ToString("dd-MM-yyyy")

(Datum is not misspelled, just Dutch)

  1. do I use the date the wrong way?
    1. if I should be using prefill that would be ok too but it is available for all registered users, so it would need to fit in the default code snippet as explained on https://github.com/2sic/2sxc/wiki/javascript-%242sxc.cms

Solution

  • Thanks Daniel, for helping out. There are 2 components to this issue. The answer to the question is: Use in the template >@entry.Datum.ToString("d") to apply the date, coming from the datePicker. The entry is a variable set in @foreach(var entry in AsDynamic(Data["Default"]))

    The other part is to prefill the date with the current date. This can be accomplished by adding a bit of code to the script to allow users to put data in the site.

     <script>
       function addProject(tag) {
            $2sxc.cms.run(tag, "new", { contentType: "Diary", prefill: { Datum: new Date().toISOString() } })
    
        }
    </script>