0

I am trying to create a "Add new" button to a column called "other Passengers" which has a "Single line of text data type". Such that I can add up "0 to n" numbers of passengers not in our LDAP i.e list of contact directory.

When the user hits the add new button another instance of that field "Other passengers" displays again. When I finished filling all the possible fields I should be able to save successfully to my SharePoint database showing all the entered passengers names in the "other passenger" in the list view or when I want to edit it too.

3
  • 1
    This is a very broad question, it would be better if you shared what you have tried so far for us to look at. Right now it looks more like an order of complete code, than an actual problem Commented May 21, 2014 at 11:30
  • Sir @Robert. What i wrote is the challenge. i am a newbi in this. and there is a request on it. i dont no what to do to get it done hence i asked the way i understood. Please i we appreciate if u can help me
    – user27012
    Commented May 21, 2014 at 11:33
  • You can try InfoPath Repeating table, search for it on Google how to use it with SharePoint Lists.. Commented May 21, 2014 at 11:37

1 Answer 1

1

You're not going to accomplish this the way you lay it out, specifically the "another instance of the Other passengers" displays again. The two viable approaches to accomplishing this would be coding a custom SPField that has an editor that would allow you to enter the other passengers as you like and just store the passengers as a delimited string under the covers. This would be a lot of work, but there are plenty of examples out there if you wanted to go that route. Here's a good starting point on MSDN:

http://msdn.microsoft.com/en-us/library/office/ms441150(v=office.14).aspx

Another approach would be to add a button to the ribbon with a custom action that pops up a simple dialog that presents the user with an editor for that field. So you would have a CustomAction with its enabled script checking to see if an item is selected, lookup the other passengers value for that item, render UI, let them edit the field, and then save it back when their done. Like the 1st approach you could just store the values in a text field with some delimiter between them for easy parsing...just pick something that is human readable as the delimiter will be visible in an item or list view.

You only need a couple lines in the enabled script:

if (SP.ListOperation.Selection.getSelectedItems().length == 1)
    return;

And you command script would just open a custom window as a SP Dialog. Here's an example for a CustomAction (just goes in the elements.xml of your SP feature):

<CustomAction
      Id="Ribbon.ListItem.Actions.YourAction"
      RegistrationType="List"
      RegistrationId="101"
      Location="CommandUI.Ribbon"
      Title="Other Passengers">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
         Location="Ribbon.ListItem.ActionsControls._children">
          <Button
            Id="MyOtherPassengers"
            Sequence="99"
            Image16by16="/_layouts/images/otherpassengers-small.png"
            Image32by32="/_layouts/images/otherpassengers.png"
            Command="otherPassengers"
            LabelText="Other Passengers"
            Description="Enter other passengers for the selected item"
            TemplateAlias="o2"/>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
          Command="otherPassengers"
          CommandAction="javascript:var options = { url: '{SiteUrl}/_layouts/OtherPassengers/Edit.aspx?lid={ListId}&amp;id={SelectedItemId}', dialogReturnValueCallback: RefreshOnDialogClose, autosize: false, title: 'Enter Other Passengers', showMaximized: true }; SP.UI.ModalDialog.showModalDialog(options);"       
          EnabledScript="javascript:enableOtherPassengers();" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>

Hope this is helpful.

4
  • Rob DÓria,I we try it now.Thanks. i we reply more either successfull or failure. Thanks again
    – user27012
    Commented May 21, 2014 at 12:46
  • Rob DÓria, I need to ask some few questions about this awesome approach. where do i include this code above
    – user27012
    Commented May 21, 2014 at 13:12
  • You'll need to create an Empty SharePoint Project in VS 2010, add a feature, and then code it from there. Start here: msdn.microsoft.com/en-us/library/office/…
    – Rob D'Oria
    Commented May 21, 2014 at 13:41
  • One more option if you don't get anywhere with the CustomAction. While it wouldn't meet your requirements 100%, you could add a Lookup column to your list/library that points at your contacts table. Just allow multiple values and it would give you something close to what you're asking for.
    – Rob D'Oria
    Commented May 21, 2014 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.