1

Firstly I have looked at this question here and here and it doesn't help with my issue:

I am using slightly modified ics.js code from here github link

var ics = function() {
'use strict';

if (navigator.userAgent.indexOf('MSIE') > -1 && navigator.userAgent.indexOf('MSIE 10') == -1) {
    console.log('Unsupported Browser');
    return;
}

var SEPARATOR = (navigator.appVersion.indexOf('Win') !== -1) ? '\r\n' : '\n';
var calendarEvents = [];
var calendarStart = [
    'BEGIN:VCALENDAR',
    'VERSION:2.0',
    'PRODID:http://www.example.com/calendarapplication/',
    'METHOD:PUBLISH'
].join(SEPARATOR);
var calendarEnd = SEPARATOR + 'END:VCALENDAR';

return {
    /**
     * Returns events array
     * @return {array} Events
     */
    'events': function() {
        return calendarEvents;
    },

    /**
     * Returns calendar
     * @return {string} Calendar in iCalendar format
     */
    'calendar': function() {
        return calendarStart + SEPARATOR + calendarEvents.join(SEPARATOR) + calendarEnd;
    },

    /**
     * Add event to the calendar
     * @param  {string} subject     Subject/Title of event
     * @param  {string} description Description of event
     * @param  {string} location    Location of event
     * @param  {string} begin       Beginning date of event
     * @param  {string} stop        Ending date of event
     */
    'addEvent': function(subject, description, location, begin, stop) {
        // I'm not in the mood to make these optional... So they are all required
        if (typeof subject === 'undefined' ||
            typeof description === 'undefined' ||
            typeof location === 'undefined' ||
            typeof begin === 'undefined' ||
            typeof stop === 'undefined'
        ) {
            return false;
        };


        var start_date = new Date(begin);
        var end_date = new Date(stop);
        var start = start_date.toISOString().replace(/-/g,'').replace(/:/g, '').replace('.000', '');
        var end = end_date.toISOString().replace(/-/g,'').replace(/:/g, '').replace('.000', '');

        var calendarEvent = [
            'BEGIN:VEVENT',
            'UID:',
            'ORGANIZER:',
            'CLASS:PUBLIC',
            'DESCRIPTION:' + description,
            'DTSTART:' + start,
            'DTEND:' + end,
            'LOCATION:' + location,
            'SUMMARY;LANGUAGE=en-us:' + subject,
            'TRANSP:TRANSPARENT',
            'END:VEVENT',
            //'END:VCALENDAR'
        ].join(SEPARATOR);


        calendarEvents.push(calendarEvent);
        return calendarEvent;
    },

This can be called in 2 ways: Hardcoding the information -

cal.addEvent('Demo Event', 'This is an all day event', 'Nome, AK', '8/7/2013', '8/7/2013');

and with passing parameters:

cal.addEvent(subject, description, location, begin, end);

With the first option the solution is provide in the question here by adding \n\n

However, I have a variable description which I pass into the second option to call this function

var description =  document.getElementById("description").value;
var subject = document.getElementById("subject").value;
var location = document.getElementById("location").value;
var begin = document.getElementById("begin").value; 
var end = document.getElementById("end").value;
var cal = ics();
cal.addEvent( subject, summary, location, begin, end);

Description is a text box that can be filled in by user and when sent to ics() will fill in the requirement for an ical for outlook. Unfortunately due to issues with description only the first line of text is sent from the textarea to the calendar entry.

I am very unsure what I need to change in the code to enable all text to be showing in the calendar entry. I am looking for a js/jquery solution. I honestly have no idea where to start to make this happen with the current code I am using.

Siobhan Holubicka
  • 147
  • 1
  • 4
  • 17

1 Answers1

1

That could be a kind of encoding problem or the content of your element "description" is not correct. Please check the content of the variable description like this:

var description =  document.getElementById("description").value;
console.log(description.split('\n').join('#NEWLINE#'));

In these ical objects, a newline or linebreak will be interpreted as the end of the description. Try to quote it with "\\n" or something like this. For more details, you have to check the specification for rfc5546 but the documentation is not very clear.

I hope this helps you further.

Community
  • 1
  • 1