web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Text field contains preceding "-" characters in D365 Portal form.

(0) ShareShare
ReportReport
Posted on by 10

I am using the below code to set the field as read only in portal form

$("#serialnumber").prop("readonly", true);
After making read only i am getting preceding character hyphen(-) on text fields like below:
pastedimage1572425655310v1.png

Anyone else experiencing this issue?

Any suggestions / help would help!!

I have the same question (0)
  • Suggested answer
    oliver.rodrigues Profile Picture
    4,052 on at

    your code works fine for me.. very odd, can you try the following:

    $("#serialnumber").attr("readonly", true);

  • Suggested answer
    Naveen Ganeshe Profile Picture
    3,397 User Group Leader on at

    Hi Kanagaraj,

    One possible reason could be these fields may be read-only in entity forms as well. I was  facing some issue like this but I have removed the div which contains the hyphens using below code:

     $("#serialnumber").next("div").remove();

  • kangaraj s Profile Picture
    10 on at

    Hi Oliver,

    Making readonly is not an issue. The issue is when we make the field as readonly on create form, we are getting dash(-) along with the value. After saving the record the dash is not showing.  I used the below code to remove dash from the field

    $("#.text-muted").hide();

    But, after that we are not able to select the lookup field also. Don't know how to hide "text-muted" class from the particular field.

  • Suggested answer
    Nicholas Hayduk Profile Picture
    2,863 on at

    As you've discovered, the dash (text-muted div) appears because the field is marked as read-only.  This is done by some JavaScript included as part of the Portal product.  It will only add that the dash if your input is read only and has no value when the code is run.

    If I had to guess, you're not putting your code that sets it to read only in a $(document).ready.  This means your code is running before the code that handles the read-only functionality.

    So you've got a couple options:

    1. Set the value of the input before you set it as read only.

    2. If you don't want that out of the box functionality, set it to be read only after that logic has already run by putting your code in a $(document).ready() like so:

    $(document).ready(function() {

    $("#serialnumber").attr("readonly", true);

    });

    Then, when the out of the box code runs, the field won't be read only yet, and the text-muted div won't be added.

    Hope that helps.

    Nick

  • Suggested answer
    Siddique mahsud Profile Picture
    11 on at

    I was facing the same issue, I have used the following workaround.

    (I faced this issue when bringing out the code, for making the field read-only, outside of a sync js API call)

    function setFieldReadOnly(fieldName) {
           $("#" + fieldName).attr("readonly", true);
          /*removing the hyphen that added after making the field readonly*/
          setTimeout( function(){$("#" + fieldName).next("div").hide()}, 300);
    }
  • Dy365Fan Profile Picture
    on at

    Thx to Muhammad. His Solution works and the "-" not showing after read-only is set.

    @Kanagaraj Pandian Please mark his answer as verified.

  • Suggested answer
    HdJ@KTC Profile Picture
    on at

    Hope this helps someone who searches for the same issue in the future. I found instead of hiding, it works better to just change the muted text color to transparent:

    $(".text-muted").css("color","transparent");

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans