Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
export class PDPFieldReader {
static get_FormFieldValue_Number = (fieldName: string, editMode: boolean): number => {
return Number(PDPFieldReader.get_FormFieldValue_Text(fieldName,editMode).replace(/[^0-9\.]+/g, ""));
}
static get_FormFieldValue_Date = (fieldName: string, editMode: boolean): Date => {
var textValue = PDPFieldReader.get_FormFieldValue_Text(fieldName, editMode);
// parsing for UK dd/mm/yyyy
var parts = textValue.split("/");
if (parts.length != 3) return new Date(0);
else
return new Date(Number(parts[2]), Number(parts[1]) - 1, Number(parts[0]));
}
static get_FormFieldValue_Text = (fieldName: string, editMode: boolean): string => {
if (editMode) {
var inputField = $('Input[Title="' + fieldName + '"]');
if (inputField.length == 0) {
console.warn("Couldn't find form field " + fieldName);
return "";
}
return inputField.val();
}
else {
var inputFieldLabel = $("H3.ms-accentText").filter(function () {
return $(this).text() == fieldName;
})
if (inputFieldLabel.length == 0) {
console.warn("Couldn't find form field " + fieldName);
return "";
}
var inputFieldValue = inputFieldLabel.closest('tr').find('td:eq(1)').find('div').first().text()
return inputFieldValue;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.