GetGroupCollectionFromUser loosing data

Feb 8, 2012 at 11:07 AM

Hi,

I run in to the issue using GetGroupCollectionFromUser if user is in the Group A then disable input to the column. However, here is my problem when user is not within this group and submit (EditForm) the item the data from the disabled columns (single line text) is wiped out. Any idea what is wrong?

 

<script type="text/javascript">


 $(document).ready(function() {

    $().SPServices({

      operation: "GetGroupCollectionFromUser",

      userLoginName: $().SPServices.SPGetCurrentUser(),

      async: false,

      completefunc: function(xData, Status) {

        if($(xData.responseXML).find("Group[Name='A']").length == 1) {

 

$(document).ready(function() {

$("input[title='Vendor']").attr('disabled','disabled');
$("select[title='Q Status']").attr('disabled','disabled');
$("input[title='Date Requested']").attr('disabled','disabled');
$("input[title='Date Received']").attr('disabled','disabled');
$("input[title='Date Entered']").attr('disabled','disabled');
$("select[title='Tooling Required']").attr('disabled','disabled');
$("input[title='User']").attr('disabled','disabled');
//$("input[title='Quantity1']").attr('disabled','disabled');
//$("input[title='Price1']").attr('disabled','disabled');
//$("input[title='Quantity2']").attr('disabled','disabled');
//$("input[title='Price2']").attr('disabled','disabled');
//$("input[title='Quantity3']").attr('disabled','disabled');
//$("input[title='Price3']").attr('disabled','disabled');
//$("input[title='Quantity4']").attr('disabled','disabled');
//$("input[title='Price4']").attr('disabled','disabled');
//$("input[title='Quantity5']").attr('disabled','disabled');
//$("input[title='Price5']").attr('disabled','disabled');
//$("select[title='Currency']").attr('disabled','disabled');

});

        }

      }

   });

});
</script>

 

Coordinator
Feb 8, 2012 at 3:04 PM

freetec:

If you disable columns, those values will not be submitted with the form. What I usually do is reenable to fields in the PreSaveAction before submitting.

Above, you are disabling the columns regardless of what you get back from the Web Service call because you have thing wrapped in a $(document).ready().

M.

Feb 8, 2012 at 4:19 PM

 

Thank you for your advice Marc :) never thought about this :/ I use quite a lot of SPServices in my projects and I think you did a brilliant job ;)

Thanks

Reagrds

Pawel

Coordinator
Feb 8, 2012 at 4:36 PM

Thanks!

M.

Feb 10, 2012 at 2:17 PM

freetec:

Have you tried to use "readonly" instead of "disabled"?  Readonly will not allow the user to edit its content, but will still submit the field information when the form is submitted...In addition, you can also attach css styling to give the fields a "disabled" look... or make it look like regular text... example:

$("input[title='Vendor']").attr('readonly','readonly').css("color", "grey");

Note: if you are using a newer version of jQuery, you may want to use .prop() when setting a field to disabled (or checked for checkboxes)... the behaviour between .attr() and .prop() changed in a recent version of jQuery (1.6 maybe? don't remember)

 

Paul T

Feb 13, 2012 at 3:12 PM

ptavares:

I have tried your solution. However, it doesn't come very good with GetGroupCollectionFromUser. For some reason doesn't apply restriction and you still can edit fields if you are not within the group :( I have used attr() haven't tried prop() . Anyway thanks for your help.

Pawel