1

I'm customizing the DisplayForm of a list, and I want put a button on footer to EditForm, but in the ctx has no edit form url and no CurrentItem.ID.

How can I do this?

1
  • 1
    ID can be retrieved from the Query String in URL
    – Asad Refai
    Commented Nov 24, 2015 at 12:47

1 Answer 1

3

Getting from ctx

var itemId = ctx.FormContext.itemAttributes.Id;

I have executed above code under OnPreRender & OnPostRender both. So you can use it where you need it.

I think it is easier to get from Query String rather than from ctx.FormContext.

As per Asad's comment, Getting from Query String

var itemId = GetUrlKeyValue('ID');

Have a look on this answer by Danny Engelman to read more about Query String.

6
  • Which one you have used? query string or ctx.FormContext.itemAttributes.Id? Commented Nov 24, 2015 at 13:24
  • For now query string. But is good to know about FormContext.itemAttributes. :D
    – Carlos
    Commented Nov 24, 2015 at 13:25
  • Hey, u know how extract the user name from user field (ctx.CurrentItem.Author)?
    – Carlos
    Commented Nov 24, 2015 at 13:26
  • use console.dir(ctx) in OnPreRender and see what's in it. I just find it (ctx.FormContext.itemAttributes.Id) this way Commented Nov 24, 2015 at 13:28
  • Author is in ctx.ListData.Items[0].Author. Commented Nov 24, 2015 at 13:31

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.