How to set the default value in a SharePoint list box depending on the value in another field?

I have my own list in SharePoint (in particular, MOSS 2007.). One field is the yes / no flag called "Any defects?" Another field is “Closed” and names the person who closed the ticket.

If there are no defects, I want the ticket to be automatically closed. If there is, then the "Closed" field should be filled in later.

I decided that I could set the calculated default value for Closed as follows:

=IF([Any defects?],"",[Me])

but SharePoint complains that I am referencing a field. I guess that makes sense; default values ​​light up when a new list item is opened first for writing and there are no values ​​in any fields.

I understand that it is possible to make a calculated field based on a column value, but in this case the field cannot be edited later.

Does anyone have any tips on how to achieve what I'm trying to do?

Is it possible to have an event like "OnSubmit" that allows me to execute some code at the save point of the list item?

Thanks.

+3
source share
3 answers

Enable the content editor web part on the page (newform.aspx / editform.aspx) and use jQuery (or just javascript) to handle the default values.

Edit: example code:

newform.aspx jquery. html, , GUID , .

, jquery, jQuery :

:

$("input[title='DISPLAYNAMEOFFIELD']"); 

id ( , :

// example field id, notice the guid and the underscores in the guid ctl00_m_g_054db6a0_0028_412d_bdc1_f2522ac3922e_ctl00_ctl04_ctl15_ctl00_ctl00_ctl04_ctl00_ctl00_TextField

$("input[id*='GUID']"); //this will get all input elements of which the id contains the specified GUID, i.e. 1 element

ready() jQuery, :

$(document).ready(function(){
 // enter code here, will be executed immediately after page has been loaded
}); 

2, onchange

$(document).ready(function(){
 $("input[title='DISPLAYNAMEOFFIELD']").change(function() 
 {
      //do something to other field here 
 });
}); 
+7

jQuery SharePoint EndUserSharePoint.com , JavaScript/jQuery.

'taming calc columns', , jQuery.

, JavaScript SharePoint DOM, - . , , , , SharePoint . , , .

+1

I am going through a code sample that might help

It sets the End Time / Date fields to Start Time + 1.5 hours when creating a new event.

It’s a bit complicated in steps, you need to do the work in time and date, but you will see examples of how to find elements in the form, as well as one way to get your script on newform.aspx without using SPD.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
</script>
<script type="text/javascript">

  // Set the hours to add - can be over 24
  var hoursToAdd = 1;
  // Mins must be 0 or div by 5, e.g. 0, 5, 10, 15 ...
  var minutesToAdd = 30;

  // JavaScript assumes dates in US format (MM/DD/YYYY)
  // Set to true to use dates in format DD/MM/YYYY
  var bUseDDMMYYYYformat = false;

  $(function() {

    // Find the start and end time/minutes dropdowns by first finding the
    // labels then using the for attribute to find the id's
    // NOTE - You will have to change this if your form uses non-standard
    // labels and/or non-english language packs
    var cboStartHours = $("#" + $("label:contains('Start Time Hours')").attr("for"));
    var cboEndHours = $("#" + $("label:contains('End Time Hours')").attr("for"));
    var cboEndMinutes = $("#" + $("label:contains('End Time Minutes')").attr("for"));

    // Set Hour
    var endHour = cboStartHours.attr("selectedIndex") + hoursToAdd;
    cboEndHours.attr("selectedIndex",endHour % 24);

    // If we have gone over the end of a day then change date
    if ((endHour / 24)>=1)
    {
        var txtEndDate = $("input[title='End Time']");
        var dtEndDate = dtParseDate(txtEndDate.val());
        if (!isNaN(dtEndDate))
        {
            dtEndDate.setDate( dtEndDate.getDate() + (endHour / 24));
            txtEndDate.val(formatDate(dtEndDate));
        }
    }

    // Setting minutes is easy!
    cboEndMinutes.val(minutesToAdd);    

});

// Some utility functions for parsing and formatting - could use a library
// such as www.datejs.com instead of this
function dtParseDate(sDate)
{
    if (bUseDDMMYYYYformat)
    {
        var A = sDate.split(/[\\\/]/);
        A = [A[1],A[0],A[2]];
        return new Date(A.join('/'));
    }
    else
        return new Date(sDate);
}

function formatDate(dtDate)
{
    if (bUseDDMMYYYYformat)
        return dtDate.getDate() + "/" + dtDate.getMonth()+1 + "/" + dtDate.getFullYear();
    else
        return dtDate.getMonth()+1 + "/" + dtDate.getDate() + "/" + dtDate.getFullYear();
}

</script>
0
source

Source: https://habr.com/ru/post/1711961/


All Articles