1

I have defined the following jQuery script to hide some columns inside my Edit & New built-in forms:-

$( document ).ready(function() {

$('.ms-formtable nobr:contains("Item Number")').closest('tr').hide();
$('.ms-formtable nobr:contains("Customer Initials")').closest('tr').hide();
$('.ms-formtable nobr:contains("Recurrence")').closest('tr').hide();
$('.ms-formtable nobr:contains("Workspace")').closest('tr').hide();
$('.ms-formtable nobr:contains("All Day Event")').closest('tr').hide();




});

now the script is working as expected inside my desktop browsers including ; IE,firefox, safari.

but when i access the Edit and New forms from my iphone 5s using safari web browser , then the script will not hide any column and all the above fields will be shown .. so can anyone adivce why the jquery script is not having any effect on iphone web browser ?

3
  • Could it be that the markup is not the same, or the DOM is not created the same way (e.g., nobr is never created either way)? You need some way of remote console, perhaps like this. Then you could inspect the DOM and run queries
    – eirikb
    Jun 8, 2015 at 6:01
  • now the custom script will work as expected if i access the pages from Safari on eithermy desktop or using PC view from my mobile. while it will not work if i switch to mobile view on my mobile device.. not sure how i can inspect the DOM on my iphone safar.. also this will raise a problem in my case if i want to be hiding the columns differently on each browser and mobile device,, so is there a more formal way to accomplish this, i mean to hide the column on the relevant New & Edit forms ?
    – John John
    Jun 8, 2015 at 11:40
  • @eirikb now i inspect the markup inside the mobile forms,, but seems i can not add custom script to the mobile forms .. as i did in the regular forms
    – John John
    Jun 10, 2015 at 15:14

2 Answers 2

1

Mobile view does not use the same markup, you can test this in your desktop browser by adding Mobile=1 to the URL.

A field will look like this:

<div class="mb-list-detail-property-panel">
        <div class="mb-list-property-name">
            UnitId
        </div><div class="mb-list-property-value">
            <input name="UnitId_TextBox" type="text" maxlength="19" id="UnitId_TextBox" /><br /><span id="ctl701" class="mb-form-field-validate" style="font-size:12px;color:red;display:none;"></span><span id="ctl702" class="mb-form-field-validate" style="font-size:12px;color:red;display:none;"></span><span id="ctl703" class="mb-form-unique-validate" style="font-size:12px;color:red;display:none;">This value already exists in the list.</span>
        </div>

Update:

You can set the ShowInNewForm/ShowInEditForm properties. This could be done with all of the object models.

Using JSOM you could do it like this:

 SP.SOD.executeFunc("sp.js", "SP.ClientContext", function() {

    var clientContext = SP.ClientContext.get_current();

    var list = clientContext.get_web().get_lists().getByTitle("ListName");

    var fields =list.get_fields();

    var fieldToHide = fields.getByInternalNameOrTitle("Field1");
    fieldToHide.setShowInEditForm(false);
    fieldToHide.setShowInNewForm(false);
    fieldToHide.update();

    clientContext.load(fieldToHide);

    clientContext.executeQueryAsync(function() { 
        console && console.log("Success");
    }, function(sender, args) {
        console && console.log("Error: " + args.get_message() + ' ' + args.get_stackTrace()); 
    });

 }); 
10
  • thanks a lot for the info about adding Mobile=1 to the URL . Now i found many online tutorials that hide columns using custom scripts same as i am currently doing. but seems those tutorials did not take into consideration mobile views, or that hiding column based on class name will not work on regular and mobile views at the same time
    – John John
    Jun 8, 2015 at 13:34
  • ...so my question is divided into two parts; how i can hide columns using javaScript and make sure that the script will work on mobile & PC views ? second question, i wrote custom script to hide these column, because these columns will be shown again when users modify them (such as changing their defualt value) so i can not reply on hiding them from the content type. so my question is what is the formal way to hide these column only from the edit & New forms , while keeping them inside the view form, other than writing custom scripts that will be rendered inside the related forms ?
    – John John
    Jun 8, 2015 at 13:36
  • 1
    What do you mean with they will be show again when they modify them, will they be show in newform/editform again then? There are properties on the fields to hide them from only newform/editform, but still visible from dispform, views etc Jun 9, 2015 at 5:36
  • 1
    @johnG updated my answer, hope its what you are looking for. Jun 9, 2015 at 15:00
  • 1
    Well, since its a property on the fields in the list, and only needs to run it one time, you could just run it from your debug console. If its a lot of list in different webs etc. You could use a powershell script. Jun 10, 2015 at 5:59
1

If it's Safari on Iphone, then add classic way of getting elements & then hide them like

document.getElementById("myDIV").style.display = "none";
2
  • can you advice why my approach will not work on iphone safari , and why i need to use document.getelementByID instead?
    – John John
    Jun 7, 2015 at 20:03
  • @Daniel Ziga now seems that the edit & new forms that are going to be rendered inside my mobile device have names different that the ones rendered inside my PC view. they will have names such as editforma.aspx & newforms.aspx and i can not access or even see these forms inside SharePoint designer,, can u adivce ? as how i will add the custom script to the mobile forms while i can not access them from the sharepoint designer?
    – John John
    Jun 9, 2015 at 23:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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