Backend InsertView with old data

Posted by Community Admin on 04-Aug-2018 15:43

Backend InsertView with old data

All Replies

Posted by Community Admin on 19-Feb-2013 00:00

Hi,

First of all sorry my bad english,

When browsing for the form to insert a new item (Create New Item - for example in the Events module) have the "event start" field populated with the current date & time, after we submit the item, we go to the list, and once again we do click on the Create new Item, the value that appears in the "event start" field is the previous value and not the current date & time.

To reload to the correct date time we need to click [CTRL]+[F5]!

Something is wrong with this behavior! 

I have javascript functions to hide or show some fields and with this behavior some times the load function is executed and other times not, causing corrupted data. :(

NS

Posted by Community Admin on 19-Feb-2013 00:00

The load function is only called once.  In the load function, attach to the bind event on the form.

This way each time form gets "re-bound" your code will run.

Posted by Community Admin on 19-Feb-2013 00:00

Hi,

Sorry but i don't understand what you mean with "In the load function, attach to the bind event on the form", the Events module is native of Sitefinity... 

Thanks,

NS

Posted by Community Admin on 19-Feb-2013 00:00

Can you post a copy of your javascript?

Posted by Community Admin on 19-Feb-2013 00:00

Hi Vitor,

My JS:

// called by the DetailFormView when it is loaded
function OnActivitiesDetailViewLoaded(sender, args)
    // the sender here is DetailFormView
    var detailFormView = sender;
 
    Sys.Application.add_init(function ()
        $create(ActivitiesSchedule.Web.UI.Backend.Scripts.ActivitiesDetailExtensions,
         _detailFormView: detailFormView ,
        ,
        ,
        null);
    );
     
    // **** 
    ShowHideEventSection(true);
    $("input[id*='activityWithRegisterFieldControl']").change(function ()
        ShowHideEventSection(!$(this).is(':checked'));
    );   
    //**********
;
 
function ShowHideEventSection(hide)
         
    if (hide)
        $('div[id*="activityEventFieldSection"]').hide();
        $('div[id*="activityEventFieldSection"]').prop('disabled', true);
    
    else
        $('div[id*="activityEventFieldSection"]').show();
        $('div[id*="activityEventFieldSection"]').prop('disabled', false);
    
 
Type.registerNamespace("ActivitiesSchedule.Web.UI.Backend.Scripts");
 
ActivitiesSchedule.Web.UI.Backend.Scripts.ActivitiesDetailExtensions = function ()
    ActivitiesSchedule.Web.UI.Backend.Scripts.ActivitiesDetailExtensions.initializeBase(this);
    // Main components
    this._detailFormView = ;
    this._binder = null;
 
    this._commandDelegate = null;
    this._dataBoundDelegate = null;
 
ActivitiesSchedule.Web.UI.Backend.Scripts.ActivitiesDetailExtensions.prototype =
    initialize: function ()
        ActivitiesSchedule.Web.UI.Backend.Scripts.ActivitiesDetailExtensions.callBaseMethod(this, "initialize");
         
        this._commandDelegate = Function.createDelegate(this, this._commandHandler);
        this._dataBoundDelegate = Function.createDelegate(this, this._dataBoundHandler);
 
        this._binder = this._detailFormView.get_binder();
 
        this._detailFormView.add_command(this._commandDelegate);
        this._detailFormView.add_onDataBind(this._dataBoundDelegate);       
    ,
 
    dispose: function ()
        if (this._detailFormView)
            this._detailFormView.remove_command(this._commandDelegate);
            this._detailFormView.remove_onDataBind(this._dataBoundDelegate);
        
        delete this._commandDelegate;
        delete this._dataBoundDelegate;
 
        ActivitiesSchedule.Web.UI.Backend.Scripts.ActivitiesDetailExtensions.callBaseMethod(this, "dispose");
    ,
 
    _dataBoundHandler: function (sender, args)        
        if (sender.get_displayMode() == Telerik.Sitefinity.Web.UI.Fields.FieldDisplayMode.Read)
            ShowHideEventSection(!args.Item.ActivityWithRegister);
        
        else
            ShowHideEventSection(!$("input[id*='activityWithRegisterFieldControl']").is(':checked'));
        
    ,
 
    _commandHandler: function (sender, args)
        var commandName = args.get_commandName();       
    
 
ActivitiesSchedule.Web.UI.Backend.Scripts.ActivitiesDetailExtensions.registerClass('ActivitiesSchedule.Web.UI.Backend.Scripts.ActivitiesDetailExtensions', Sys.Component, Sys.IDisposable);

the call in DefineBackendInsertView:

....
ClientScriptElement activitiesDetailExtensions = new ClientScriptElement(activityScheduleEditDetailView.Scripts)
            
                ScriptLocation = "ActivitiesSchedule.Web.UI.Backend.Scripts.ActivitiesDetailExtensions.js, ActivitiesSchedule",
                LoadMethodName = "OnActivitiesDetailViewLoaded"
            ;
activityScheduleInsertDetailView.Scripts.Add(activitiesDetailExtensions);
...

Anyway the behavior I have in my module also exists in the Event module of Sitefinity.

Posted by Community Admin on 19-Feb-2013 00:00

If I understand correctly, you can try this:

Add the following lines to the OnActivitiesDetailViewLoaded function:

var binder = sender.get_binder();
binder.add_onDataBound(Binder_OnBind);

Then make a new function and put the call to ShowHideEventSection inside:

function Binder_OnBind(sender, args)

     ShowHideEventSection(true);

Posted by Community Admin on 19-Feb-2013 00:00

FWIW, after testing this, add_onDataBound isn't called on the InsertView, only the EditView.  Maybe someone else can chime in here on the correct event??

Posted by Community Admin on 19-Feb-2013 00:00

Hi Vitor, 

Thank you for your help but the behavior is the same... i put a break point in the function Binder_OnBind and it never stoped in the breakpoint...

Please follow this steps (forget the javascript for this example):

1º Go to Content -> Events

2º Create an event, fill the fields and do not change the field "event start" but memorized it and published the event.

3º Wait a minute, now in the list view click again in create an event, check the value of the field "event start": is the same value? Should not be, because the current time is one minute older.


NS

Posted by Community Admin on 22-Feb-2013 00:00

Some help please??

NS

Posted by Community Admin on 22-Feb-2013 00:00

Hi guys,

The reason for this is that the caching is done on content module level and so when you are under the current module (for example Events) your custom JS will execute only once (called from certain view) because after the first call it will stay cached. If you navigate out of the module and then go back and create an Event the cache will be cleared in the meantime and the custom JS will be executed once more, also the start date field will be changed - see video

This is core Sitefinity functionality and it cannot be overridden. You could try to create a button on the Insert and/or Edit view and call your JS by pressing it. This way you can execute the code when you need it, but it will require user intervention.

Regards,
Pavel Benov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 01-Mar-2013 00:00

So how is a feature and can not be overridden, put a button. Is this some kind of joke, right?

Thanks for the help,

NS

Posted by Community Admin on 05-Mar-2013 00:00

Hello Nuno,

What I meant is that you cannot fully automate the process and in any case a user intervention will be required in order to get the correct time. Either by navigating out of the News module, or creating a button on the Insert view which will invoke your Javascript function to refresh the time.

Kind regards,
Pavel Benov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed