Jump to content

Repeater: Open new item automaticly


planmacher
 Share

Recommended Posts

Hi! Hope somebody can help me ...

I don't want the user to have to click on the "add new repeater item link" but would like to open it automaticly when loading the edit page. (Best would be, if this only happens if the new item would be the first item) 

Tried to do it with triggering the click of the add-new-item-link with javascript. But this does'nt seem to work. My java script knowledge is really poor :-(

Or do I just missed something in the settings of the repeater-field???

Thanks for any feedback!

Link to comment
Share on other sites

This should do the job:

$(window).load(function(){
    var $repeater_wrap = $('#wrap_Inputfield_YOUR_REPEATER_FIELD_NAME');
    if($repeater_wrap.length && !$repeater_wrap.find('.InputfieldRepeaterItem').not('.InputfieldRepeaterNewItem').length) {
        $repeater_wrap.find('.InputfieldRepeaterAddLink').trigger('click');
    }
});

It won't work for nested repeaters though - for that you'd have some more work to do, ensuring you get direct child elements of $repeater_wrap, and dealing with the fact that inputfields inside a repeater item have changed names. 

But it may not be such a good idea to open a new repeater item on page load. The issue is that you are actually creating a new repeater item when you do this, so that if the user saves without filling out the repeater fields you will end up with a blank item. And if any of the fields in the repeater are required the user will see error messages.

Link to comment
Share on other sites

On 10.8.2017 at 11:35 PM, Robin S said:

But it may not be such a good idea to open a new repeater item on page load. The issue is that you are actually creating a new repeater item when you do this, so that if the user saves without filling out the repeater fields you will end up with a blank item. And if any of the fields in the repeater are required the user will see error messages.

Thanks alot and please excuse my late response!!
You are right - not a good Idea - I realised it by myself, that there is an new repeater Item created by opening the input mask. Nevertheless its good to know, how to do it - will give it a try - and its great to see, that there is such a great community with a lot of help here.
 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...