Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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:

share|improve this question

3 Answers 3

up vote 3 down vote accepted

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();"
share|improve this answer
    
now it says, return statement out of function? –  Esteban V 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. –  Esteban V 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. –  Esteban V Mar 8 '12 at 13:53
1  
+1 for finding the missing function. :) –  Deepu Nair Mar 8 '12 at 15:12

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.

share|improve this answer
    
please see my update, however its not working, the button is always disabled no matter what I select, I dont have javascript errors anymore –  Esteban V Mar 8 '12 at 12:07

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();"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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