2

I got the following code in my elements.xml, but I cant find the error.

My ribbon is broken, the error says, expected;.

But I see no error, yet, maybe fresh eyes can see it. See the EnabledScript section:

3

You can't use int in javascript: javascript: for (int i =0; i < items.length; i++) { if (items[i].fsObjType == 1) return false; } return true;

with:

javascript:
for (var i =0; i &lt; items.length; i++)
{
        if (items[i].fsObjType == 1)
             return false;
}
return true;

UPDATE After the update of the question: You define your function in EnabledScript but you never invoke this. According to msdn example you have to invoke it:

EnabledScript="javascript:function SomeAppropriateNamForFunction()
{
    var items = SP.ListOperation.Selection.getSelectedItems();
    for (var i =0; i &lt; items.length; i++)
    {
            if (items[i].fsObjType == 1)
                 return false;
    }
    return true;
}
SomeAppropriateNamForFunction();"
  • now it says, return statement out of function? – Luis Valencia Mar 8 '12 at 11:26
  • I updated the question with the current code in the enabled script, but it doesnt down what is needed to do. – Luis Valencia Mar 8 '12 at 11:38
  • According to msdn example, you have to invoke your function as well. See my updated answer. – Anatoly Mironov Mar 8 '12 at 12:34
  • lol indeed, thanks for your answer, it works perfect now. – Luis Valencia Mar 8 '12 at 13:53
  • 1
    +1 for finding the missing function. :) – Deepu Nair Mar 8 '12 at 15:12
1

Problem is here:

 EnabledScript="javascript:
              for (int i =0; i &lt; items.length; i++)
              {
                  if (items[i].fsObjType == 1)
                     return false;
              }
              return true;"/>

items is unassigned variable.

  • please see my update, however its not working, the button is always disabled no matter what I select, I dont have javascript errors anymore – Luis Valencia Mar 8 '12 at 12:07
1

Try this:

  EnabledScript="javascript: function isNonFolderSelected() {
                  var selectedItems = SP.ListOperation.Selection.getSelectedItems();
                  var result = true;
                  for (var i = 0; i &lt; selectedItems.length; i++) {
                      // it is a list item, not a folder
                      if (selectedItems[i].fsObjType == '1') {
                          result = false;
                          break;
                      }
                  }
                  return result;
              }
              isNonFolderSelected();"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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