0

I have a site in Sharepoint Online, which is used for requests for a notary service, I have entered the following code in order to show a field once an option of a previous field has been chosen "Es urgente?".

In ShowSPField you can see the "Razón de la urgencia" field. The objective is to make this field mandatory when the option of the "Es urgente?" Field is selected.

I have looked for ways, without success.

<WebPartPages:ScriptEditorWebPart runat="server" Content="&lt;script src=&quot;//code.jquery.com/jquery-1.10.1.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://xxxx/Notariado/SiteAssets/sputility.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://xxxx/Notariado/SiteAssets/sputility.js&quot;&gt;&lt;/script&gt;

&lt;script&gt;
// wait for the window to load
$(document).ready(function () {
    // Get a single select dropdown field
    var relacionField = SPUtility.GetSPField(&#39;Es urgente?&#39;);

    // create a function to show or hide Rates based on Rate value
    var showOrHideField = function() {
        var relacionFieldValue = relacionField.GetValue();
        // Hide the Rates field if the selected value is Especial
        if(relacionFieldValue === &#39;S&#237;&#39;) {
            SPUtility.ShowSPField(&#39;Raz&#243;n de la urgencia&#39;);
        }
        else {
            SPUtility.HideSPField(&#39;Raz&#243;n de la urgencia&#39;);
        }
    };

    // run at startup (for edit form)
    showOrHideField();

    // make sure if the user changes the value we handle it
    $(relacionField.Dropdown).on(&#39;change&#39;, showOrHideField);
});
&lt;/script&gt;" ChromeType="None" Description="Permite a los autores insertar fragmentos de HTML o secuencias de comandos." ImportErrorMessage="No se puede importar este elemento web." Title="Editor de secuencias de comandos" ID="g_d15e43fb_3989_47c8_9dfc_f765966b2a41" __MarkupType="vsattributemarkup" __WebPartId="{D15E43FB-3989-47C8-9DFC-F765966B2A41}" WebPart="true" __designer:IsClosed="false" partorder="6"></WebPartPages:ScriptEditorWebPart>

0

You could use PreSaveAction function. PreSaveAction function used for client side validation commonly.

Here is my test code :

<script src="https://cdn.bootcss.com/jquery/3.4.0/jquery.js"></script>
<script src="https://xxxxx.sharepoint.com/sites/dev/SiteAssets/sputility.js"></script>

<script>
    var isSelected=false;
$(document).ready(function () {
    // Get a single select dropdown field
    var relacionField = SPUtility.GetSPField('Es urgente?');

    // create a function to show or hide Rates based on Rate value
    var showOrHideField = function() {
        var relacionFieldValue = relacionField.GetValue();
        // Hide the Rates field if the selected value is Especial
        if(relacionFieldValue === 'Sí') {
            SPUtility.ShowSPField('Razón de la urgencia')

        }
        else {
            SPUtility.HideSPField('Razón de la urgencia')
        }
    };

    // run at startup (for edit form)
    showOrHideField();

    // make sure if the user changes the value we handle it
    $(relacionField.Dropdown).on('change', showOrHideField);


});
function PreSaveAction() {   
    var Field = SPUtility.GetSPField('Razón de la urgencia');
            if(Field.GetValue()==""){
                isSelected=true;
            }
        if (isSelected)  
    {  
        isSelected=false
        alert("Please input Razón de la urgencia value. ")
         return false;  
    }  
    else  
    {  
        return true;  
    } 
}
</script>

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.