Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

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

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!!

  • Suggested answer
    HdJ@KTC Profile Picture
    HdJ@KTC on at
    RE: Text field contains preceding "-" characters in D365 Portal form.

    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");

  • Dy365Fan Profile Picture
    Dy365Fan on at
    RE: Text field contains preceding "-" characters in D365 Portal form.

    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
    Siddique mahsud Profile Picture
    Siddique mahsud 11 on at
    RE: Text field contains preceding "-" characters in D365 Portal form.

    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);
    }
  • Suggested answer
    Nicholas Hayduk Profile Picture
    Nicholas Hayduk 2,863 on at
    RE: Text field contains preceding "-" characters in D365 Portal form.

    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

  • kangaraj s Profile Picture
    kangaraj s 10 on at
    RE: Text field contains preceding "-" characters in D365 Portal form.

    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
    Naveen Ganeshe Profile Picture
    Naveen Ganeshe 3,393 User Group Leader on at
    RE: Text field contains preceding "-" characters in D365 Portal form.

    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();

  • Suggested answer
    oliver.rodrigues Profile Picture
    oliver.rodrigues 4,052 on at
    RE: Text field contains preceding "-" characters in D365 Portal form.

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

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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans